开发者

Include Obj-C++ header from C++ source file

Consider the followng situation:

MacFont.h

struct MacFont : Font
{
  // ...

  NSFont* font;
};

MacFont will be implemented in MacFont.mm

FontEngine.cpp:

#if defined(OS_MAC)开发者_如何学运维
#include "MacFont.h"
#elif
// ...
#endif

//...

In order to make it compiling, I should rename FontEngine.cpp to FontEngine.mm but I'm not allowed to.

So what now?


If you cannot change the filename, don't fret. Consult your compiler manual for an option to force the filetype, and tell the compiler that this file, regardless of extension, is an Objective-C++ file.


You can only compile ObjC things (e.g. NSFont) into a ObjC file (ir .m or .mm) so you can only do the rename.

You could create another C++ object inheriting from the C++ object in FontEngine.cpp and then that C++ object can have implementation including Obj C parts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜