【问题标题】:Export template function导出模板功能
【发布时间】:2011-05-28 17:51:45
【问题描述】:

我有templated functionconnect:

template<class InstanceClass>
CL_Slot connect (InstanceClass *instance, void(InstanceClass::*function)(Param1, Param2))

它连接来自InstanceClass的一些信号传递函数。

在我的示例中,我想为键盘事件 (KeyDown) 连接一些类。 在 C++ 中我写:

get_signal_object().connect(&SomeClass::func);

但是我必须在 python-script 中使用这个函数并从 c++ 代码中导出(使用 boost.python)。

据我所知,要导出模板,我必须通过任何使用的类型来导出它。但在 python 中,我将传递仅存在于 python-namespace 中的类。

那么,有什么想法可以在 python 中使用模板化的函数吗?

【问题讨论】:

    标签: c++ python templates boost export


    【解决方案1】:

    你为什么不直接添加

    extern template<>
        CL_Slot connect<SomeClass> (SomeClass *instance, void(InstanceClass::*function)(Param1, Param2));
    

    注意:extern 可能需要在template&lt;&gt; 之后——不记得了

    如果你必须有 C 链接添加一个包装函数(它将内联模板化函数)。


    注意:MSVC 有nonstandard template export facilities

    c++0x 即将支持外部模板:http://en.wikipedia.org/wiki/C%2B%2B0x#Extern_template

    【讨论】:

    猜你喜欢
    • 2021-09-10
    • 1970-01-01
    • 2012-08-16
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    相关资源
    最近更新 更多