这是我的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”,我使用“使用MP;”在c#中。 通过这个,我能够调用exFunction而不是其他类是模板类。我该如何调用模板类?
答案 0 :(得分:4)
在C ++ / CLI dll中,改为使用'generic':
generic<class Type>
public ref class linkedList
对此有一些澄清:C ++ / CLI允许“模板”和“通用” - “模板”的工作方式与典型的本机C ++模板类似,而“通用”则类似于C#中的泛型。