基本类型在c ++和CLI之间传递模板参数 [英] Primitive types pass template parameter between c++ and CLI

查看:121
本文介绍了基本类型在c ++和CLI之间传递模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c ++模板类:

I have a c++ templated class:

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

但我需要在CLI中包装它,所以它可以在c#中使用。

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

示例:

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);



如果我使用CLI模板 ref class ,它调用模板化的c ++方法,原始类型生成正确的c ++模板代码编译? - >

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 ?->

推荐答案

在C#中使用的是泛型,而不是模板。没有办法专门从C#的C ++ / CLI模板。

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

这篇关于基本类型在c ++和CLI之间传递模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆