Objective-C++ compilation errors due to Xcode not respecting file type -
i'm following tutorial in book (iphone 3d programming), uses:
- objective-c header , source files (file extensions .h, .m - respectively),
- objective-c++ header , source files (file extensions .h, .mm - respectively)
- c++ header , source files (file extensions .hpp, .mpp - respectively)
a sample xcode project included compiles successfully.
before found sample project, had manually typed out code book getting following compilation errors files detailed below:
- unknown type name 'virtual'
- expected member name or ';' after declaration specifiers
irenderingengine.hpp (xcode file inspector - file type = "default - c++ header")
... struct irenderingengine { virtual void initialize(int width, int height) = 0; //2 errors marked above virtual void render() const = 0; //2 errors marked above virtual void updateanimation(float timestep) = 0; //2 errors marked above virtual void onrotate(deviceorientation neworientation) = 0; //2 errors marked above virtual ~irenderingengine() {} //2 errors marked above }; ...
- must use 'struct' tag refer type 'irenderingengine'
glview.h (xcode file inspector - file type = "default - c header")
#import "irenderingengine.hpp" #import <quartzcore/quartzcore.h> @interface glview : uiview { @private eaglcontext* m_context; irenderingengine* m_renderingengine; //1 error marked above float m_timestamp; } - (void) drawview:(cadisplaylink*)displaylink; - (void) didrotate:(nsnotification*)notification; @end
the file types other files defaulted expected file types in xcode file inspector , such should have worked correctly build setting - apple llvm compiler 4.2 - language - "compile sources = according file type" - identical build setting in sample project compiles successfully.
for odd reason changing build setting "compile sources = objective-c++" in manually created project removed compilation errors , application ran expected.
can offer reason why setting not consistent between seemingly identical (source-code-wise) projects?
header files not compiled. header files used preprocessor — anywhere have #include
or #import
actual text of original treated though you'd copied , pasted original.
hence doesn't matter if file called .hpp, .h or else. if .m file imports .h file includes .hpp file .hpp code compiled part of .m file, i.e. objective-c.
i therefore going guess you've got glview.m
. if that's going import .hpp file, whether directly or indirectly, needs compiled objective-c++. 1 way rename .mm, other tell project not try guess language types file extension.
Comments
Post a Comment