Primitive types pass template parameter between c++ and CLI

这一生的挚爱 提交于 2019-12-02 04:28:43

问题


I have a c++ templated class:

template<class T>
class A {
    void test (T temp) { }
};

But i need to wrap it in CLI so it can be used in c#.

Example:

CLI:

template<class T>
ref class AWrap {
     private:
        A* a;
     public:
        void test (T temp) { 
           a->test<T>(temp);
        }
};

C#:

Awrap blah = new AWrap();
blah<int>(3);

If I make a CLI templated ref class , which call the templated c++ method, will the primitive types generate the right c++ templated code on compilation ?->


回答1:


What you are using in C# are generics, not templates. There is no way of specializing a C++/CLI template from C#.



来源:https://stackoverflow.com/questions/4735507/primitive-types-pass-template-parameter-between-c-and-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!