[英]C++ CLR Managed DLL containing template classes to be used in C#
这是我的dll中的模板类之一:
template <class Type>
public ref class linkedList {
protected:
nodeType<Type>^ head;
nodeType<Type>^ tail;
public:
linkedList();
linkedList(const nodeType<Type>^newHead);
nodeType<Type>^ getHead() { return head; }
nodeType<Type>^ getTail() { return tail; }
void push(const Type item);
Type pop();
bool isEmpty();
void refreshTail();
void print();
void destroy();
void appendToTail(nodeType<Type>^const newNode);
~linkedList();
};
这已经定义。 但是,当我引用dll时,其命名空间不会显示。 我试图添加这样的非模板类:
public ref class number{
private: int x;
public: void exFunction(int y){ x=y;}
};
然后出现名称空间。 可以说名称空间是“ MP”,我使用“ using MP;”。 在C#中。 通过这样做,我能够调用exFunction,但不能调用模板类的其他类。 如何调用模板类?
在您的C ++ / CLI dll中,改用'generic':
generic<class Type>
public ref class linkedList
在此方面的一些澄清:C ++ / CLI允许“模板”和“通用”-“模板”的工作方式类似于典型的本机C ++模板,而“通用”的工作方式类似于C#中的泛型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.