首先是OC調用C++的代碼。 創建一個Objective-C的項目,並創建c++文件MyCppFile.hpp和MyCppFile.cpp。 把要調用Cpp代碼的文件名改成mm尾碼名,項目代碼的結構如下: 實現C++部分的代碼: MyCppFile.hpp MyCppFile.cpp 在main.m ...
首先是OC調用C++的代碼。 創建一個Objective-C的項目,並創建c++文件MyCppFile.hpp和MyCppFile.cpp。





實現C++部分的代碼: MyCppFile.hpp






然後是C++調用OC 先創建OC相關的文件,然後把*.m修改為*.mm。
.png)

頭文件用C的格式來進行編寫 MyOCFile.h

用OC編寫具體的實現。




OC和C++間的調用比想象中的要簡單,這裡的關鍵是要把OC的文件的擴展名修改為*.mm。