Reputation: 43
TestViewController.h/TestViewController.mm
HelloWorld.h/HelloWorld.cpp
If I include "HelloWorld.h" into TestViewController.mm it compiles well. When I include "HelloWorld.h" into TestViewController.h it prompts an error: 'iostream' file not found.
My HelloWorld.h code is a simple standard cpp file.
#ifndef __MixedCppTest__HelloWorld__
#define __MixedCppTest__HelloWorld__
#include <iostream>
#include <vector>
class HelloWorld {
public:
HelloWorld();
~HelloWorld();
};
#endif /* defined(__MixedCppTest__HelloWorld__) */
Upvotes: 0
Views: 4047
Reputation: 43
Thanks https://stackoverflow.com/users/635608/mat 's answer.
It has only one standard solution, that's make compiler knows about specified sources should be compiled as objective-c++.
There are only 3 ways:
change .m to .mm
change Type to Objective-c++ in Utilities panel in xcode editor.
change "Compile sources as" to objective-c++
If you import cpp file indirectly, you should change all files to objective-c++ compiled mode on the import chain.
Upvotes: 0
Reputation: 138
When I include "HelloWorld.h" into TestViewController.h it prompt error: 'iostream' file not found….
Is there any Objective-C files which imports TestViewController.h? At the stage of preprocessing header file becomes a part(along with the source file) of a translation unit, and if you're asking to include such header (with c++ libraries inclusion and c++ class definition) to Objective-C source file - then no, it's impossible. If you searching a way to compile and link .cpp and .m source files to one binary, you could make .mm wrapper unit to wire them together.
Upvotes: 0