C++/CLI创建的函数:点在C#项目不同于一般类型名在C++/CLI
public interface class ITest{
public:
virtual void doSomething(){
}
}
public ref Base {
...........
...........
}
generic <typename T> where T : ITest
public ref Derived : Base{
public:
virtual void doNothing(){
}
}
public ref AnotherClass {
public:
generic<class T> where T : Base
static int justDoThis(){
//Problem!!
}
}
C#:
在C#中有两班A
和B
。 A
继承自ITest
和B
继承自Derived
,其中A
用作类型名称。另外,B
有一个类型为A
的私有变量。因此,从主函数AnotherClass.justDoThis<B>()
被调用,其中B
作为泛型传递。
“//问题!!”部分:
现在我必须在本节中创建一个B
的新实例,并访问A
这是B
中的私有变量。
你好,我是C++/CLI的新手。感谢您的回复,但问题1是不可能的。正如构建错误时显示的那样:不能使用gcnew来分配泛型类型。我正在使用safe_cast(System :: Activator :: CreateInstance(TService :: typeid))。我现在想做2件事。首先将此遗传传递给另一个没有where子句的泛型函数。其次,在另一个函数中,我想使用覆盖功能,这是从ITest –
user6924365
中写入的A什么是“TService”?你的问题中没有“TService”。另外,请每个帖子提问一次,不要在同一帖子中添加更多问题。 –
这是T.对不起。我给出了泛型类型的错误名称。你能回答这个问题吗?我需要答案。 :-) – user6924365