C++ mixed with oc

 

1.oc calls c++:

1. Create a new ios project

2. Create a new c++ file, including hpp file and cpp file, named MyCppFile.hpp, MyCppFile.cpp

hpp file:

 

cpp file:

3. Modify ViewController.m to: ViewController.mm file

4. The ViewController.m file executes MyCppClass::ShowMsg() to complete the call;

2. c++ calls oc

1. Create a new ios file: MyOcFile.h, MyOcFile.mm

2. Remove the interface of MyOcFile.h, move #import <Foundation/Foundation.h> to MyOcFile.mm, and declare a c function showOCMsg()

The .mm file is as follows

3. The c++ file imports the oc file #include "MyOCFile.h", and then calls showOCMsg

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325854687&siteId=291194637