Xcode #include strangeness
I've got one file where I've put all my user defined types
into. It is named TypeDefs.h
typedef int myType; // one of many user types.
----------------------------------
Source File: MySource.cpp
#include "TypeDefs.h"
myType heyThere; //compiler error: myType does not name a type.
----------------------------------
It's so simple, that I think something very subtle is going on.
I've got many other source files which #include the TypeDefs.h file
with no problems whatsoever. I even just copied and pasted the
typedef directly into the Source file and then the compile works fine.
I'm thinking that Xcode for some reason is simpling not #including the
header file TypeDefs.h. Maybe I've turned off including without
realizing it? Is there a way within Xcode to verify that TypeDefs.h is
being included?
into. It is named TypeDefs.h
typedef int myType; // one of many user types.
----------------------------------
Source File: MySource.cpp
#include "TypeDefs.h"
myType heyThere; //compiler error: myType does not name a type.
----------------------------------
It's so simple, that I think something very subtle is going on.
I've got many other source files which #include the TypeDefs.h file
with no problems whatsoever. I even just copied and pasted the
typedef directly into the Source file and then the compile works fine.
I'm thinking that Xcode for some reason is simpling not #including the
header file TypeDefs.h. Maybe I've turned off including without
realizing it? Is there a way within Xcode to verify that TypeDefs.h is
being included?
Try putting #pragma once at the top of your header. It might work.
Should typedefs go into .h header files or .cpp files? Looking at the typedef statement, lets
take a real simple example:
typedef int Integer;
There is no memory allocated at this time, so that makes it a declaration; Therefore
it should go in the .h file. Right?
take a real simple example:
typedef int Integer;
There is no memory allocated at this time, so that makes it a declaration; Therefore
it should go in the .h file. Right?
Questions like that show a fundamental misunderstanding of how "headers" work.
Use the "Preprocess" command in Xcode (or the -E flag to gcc) to see the source that's making it to the compiler. Hopefully that should clear up your understanding.
Use the "Preprocess" command in Xcode (or the -E flag to gcc) to see the source that's making it to the compiler. Hopefully that should clear up your understanding.
Besides that being a pretty pointless declaration, the rule is that public declarations (the typedefs and prototypes you want to use in other modules) go into the header, all the private stuff and definitions go into the implementation file.
Also, note that #pragma once is sort of deprecated (i use it, though), but you can also use
as a "header guard".
Also, note that #pragma once is sort of deprecated (i use it, though), but you can also use
PHP Code:
#ifndef __MYFILE_H__
#define __MYFILE_H__
/*code goes here*/
#endif
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| StorageRoom - Include content in your games | sashthebash | 0 | 2,104 |
Jun 13, 2011 05:39 AM Last Post: sashthebash |
|
| #include <ft2build.h> | BBBert | 4 | 9,923 |
Apr 7, 2008 09:33 AM Last Post: BBBert |
|
| Newbie problem XCode Include files | BBBert | 1 | 3,843 |
Mar 17, 2008 03:46 PM Last Post: OneSadCookie |
|
| Fixing Include Paths | vbuser1338 | 4 | 2,833 |
May 28, 2006 05:15 PM Last Post: vbuser1338 |
|
| 3 line OpenGL strangeness....? | WhatMeWorry | 1 | 2,819 |
Jul 2, 2005 07:15 PM Last Post: OneSadCookie |
|

