Primitive types pass template parameter between c+

2020-04-14 16:04发布

问题:

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#.