How can I use C++ with Objective-C in XCode

后端 未结 2 1617
南方客
南方客 2020-11-29 09:22

I want to use/reuse C++ object with Objective-C. I have a hello.h that has the class definition, and hello.cpp for class implementation.

class Hello
{ int ge         


        
相关标签:
2条回答
  • 2020-11-29 09:53

    Make sure you compile that file as "Objective-C++".

    The simplest way is to rename it as *.mm.

    If you don't want to rename the *.m file,

    1. Select your file.
    2. Open the File Info dialog (Cmd+I)
    3. In File Type, select "sourcecode.cpp.objcpp"
    0 讨论(0)
  • 2020-11-29 10:00

    Rename the Objective-C file from filename.m to filename.mm to make it compile as Objective-C++.

    0 讨论(0)
提交回复
热议问题