ios c++ 调用oc代码

来源:互联网 发布:淘宝网鲜花图片素材 编辑:程序博客网 时间:2024/05/20 23:34
今天照猫画虎的用c++调用了一段oc代码,需要注意的一点是为了混编,.cpp文件后缀要改为.mm,其他的就按照oc跟c++语法使用就是了 

C++代码  收藏代码
  1. //  
  2. //  MKStoreForCpp.h  
  3. //  
  4.   
  5. #ifndef SGR_MKStoreForCpp_h  
  6. #define SGR_MKStoreForCpp_h  
  7.   
  8. class MKStoreForCpp {  
  9.   
  10. public:  
  11.     inline static MKStoreForCpp&  instance()  
  12.     {  
  13.         static MKStoreForCpp  mkStoreForCpp;  
  14.         return mkStoreForCpp;  
  15.     }  
  16. public:  
  17.     void  buyFeature(const  char* feature);  
  18.       
  19. };  
  20.   
  21. #endif  


C++代码  收藏代码
  1. //  
  2. //  MKStoreForCpp.mm  
  3. //    
  4.   
  5. #include "MKStoreForCpp.h"  
  6. #include "MKStoreManager.h"  
  7.   
  8. void   MKStoreForCpp::buyFeature(const  char* feature)  
  9. {  
  10.     [[MKStoreManager sharedManager] buyFeature: [NSString stringWithUTF8String: feature]];  
  11. }  
原创粉丝点击