Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ssawgift

macrumors newbie
Original poster
Mar 23, 2012
8
0
I know I can include standard C++ header inside a .mm source file.

But now I need to include a C++ header file inside an objc header file. Is it supported to do so?
 
If you do you need to be sure that this file is only #imported into .mm files that will be compiled as Objective-C++. #ifdef __cplusplus could be used to conditionally include C++ portions if the file may be imported in a .m.

-Lee
 
Last edited:
I know I can include standard C++ header inside a .mm source file.

But now I need to include a C++ header file inside an objc header file. Is it supported to do so?

The problem is not including a C++ header from an Objective-C header, the problem is including a C++ header directly or indirectly from a C or Objective-C source file. C and Objective-C source files are exactly the same in this respect.

You can't include class definitions from C. If you include function declarations without precautions, then C and Objective-C will interpret them as C functions, while C++ and Objective-C++ will interpret them as C++ functions, so they need to be declared as "extern "C"" when included from C++.

So unless the author of the header file was planning for this, it won't work.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.