【问题标题】:objective-c wrapper for namespaced c++ library (gloox)命名空间 c++ 库 (gloox) 的目标 c 包装器
【发布时间】:2011-08-31 22:58:19
【问题描述】:

我试图将 gloox 库包装在 Objective-c 中。我已经阅读了这篇文章Making a Objective-C Wrapper for a C++ Library,它相当简单,但是它不包括命名空间内的类。关于如何仅将上述文章中的技术与命名空间一起使用的任何想法? 感谢您的帮助!

[编辑] 想我想通了 添加

#ifdef __cplusplus
namespace gloox {
class Client;
}
#endif

【问题讨论】:

    标签: c++ objective-c namespaces wrapper


    【解决方案1】:

    我认为当编译为目标 C++ 时,显而易见的应该可以工作:

    #if defined __cplusplus
    namespace Foo { class MyCPPClass; }   // forward class declaration
    #else
    /*not sure here*/ /*namespace Foo { typedef struct MyCPPClass MyCPPClass;  }*/ // forward struct declaration
    #endif
    
    @interface MyOCClass : NSObject
    {
    @private
        Foo::MyCPPClass* cppObject;
    } 
    
    // methods and properties
    
    @end
    

    Qt 项目中有很多 examples 用于混合 C++ 和 Objective-C。

    【讨论】:

    • 我还发现了另一种方法,您也可以将实例声明包装在#ifdef 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 2014-01-14
    • 1970-01-01
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多