Problem when #import C++ Header File in iPhone/iPad Project -


i have c++ class use in iphone/ipad project.
created file in different ways (like "new file" => c++) , error same.

when compile project without having #import (of .h c++ class), it's ok.

but #import header file in 1 of header objective-c file, error :

error: vector: no such file or directory

or

error: expected '=', ',', ';', 'asm' or 'attribute' before ':' token"

i tried setting different values file type (of c++ class) in file info, renaming objc class in .mm etc, doesn't seem work.

so must have missed importing .h c++ class in objc header file, :p ^^

solution vlad
1°) include header c++ file :

#ifdef __cplusplus     #include "triangulate.h" #endif 

2°) renaming objc file in .mm , in file info (right clic) setting file type sourcecode.cpp.objcpp

thanks helping !
vincent

note: xcode requires file names have “.mm” extension objective-c++ extensions enabled compiler.

trying use c++ in objective-c code residing in file .m extension probable cause of problem because compiler not recognize c++ constructs according error message. renaming .m file .mm should help.

for more details, see using c++ objective-c.

assuming want use objective-c class in objective-c++ source file, there's no problem @ all. restriction .h file must objective-c clean. means can't use c++-isms in it, or if must wrap them in #ifdef __cplusplus. header compiled in objc mode when it's #included plain objective-c file, has eliminate c++isms situation (1). objective-c header file should include c++ header this:

#ifdef __cplusplus # include mycppheader.h #endif 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -