.net 接口与通用方法,实现中的错误
请记住,这段代码可以在 C# 中运行,但不能在 VC++.net 中运行(令人愤怒)。我想知道我的错误在哪里。
给定代码:
public interface class iTest
{
public:
generic <typename T>
virtual void AddCriteriaList(List<T> ^CriterionList);
};
generic <typename Q>
public ref class IUseInterface : iTest
{
public:
generic <typename T>
virtual void AddCriteriaList(List<T> ^CriterionList)
{
}
};
我收到错误 error C3766: 'IUseInterface' Must Provide an implementation for the interface method 'void iTest::AddCriteriaList(System::Collections::Generic::List ^)'
奇怪的是,如果我删除IUseInterface 上的通用约束 (Q),错误就会消失。我不明白如何使我的类泛型与特定函数的泛型有任何关系。
有什么想法吗?谢谢
Bear in mind, this code works in C#, but not in VC++.net (infuriating). I'm wondering where my mistake is on here.
Given the code:
public interface class iTest
{
public:
generic <typename T>
virtual void AddCriteriaList(List<T> ^CriterionList);
};
generic <typename Q>
public ref class IUseInterface : iTest
{
public:
generic <typename T>
virtual void AddCriteriaList(List<T> ^CriterionList)
{
}
};
I get the error error C3766: 'IUseInterface' must provide an implementation for the interface method 'void iTest::AddCriteriaList(System::Collections::Generic::List ^)'
The strange thing, is if I remove the generic constraint (Q) on IUseInterface, the error goes away. I don't understand how making my class generic would have ANYTHING to do with a generic on a specific function.
Any ideas? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,如果不使用 List 参数而只使用 T 参数,编译似乎就很好。只需使用将它们全部添加到循环或其他内容中即可,它是几行额外的代码,但会为您编译。
Well, it seems to compile just fine if you don't use a List parameter, and just use a T parameter. Just use add them all in a loop or something, its a few lines of extra code, but will compile for you.
我没有答案,但如果它对你来说足够好的话,这是可行的:
I don't have the answer for that, but this works, if it's good enough for you: