开发者

.net interfaces with generic methods, errors in implementation

开发者 https://www.devze.com 2023-03-06 23:42 出处:网络
Bear in mind, this code works in C#, but not in VC++.net (infuriating).I\'m wondering where my mistake is on here.

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 <typena开发者_StackOverflow社区me 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


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:

generic <typename T>
public interface class iTest
{
   public:
   virtual void AddCriteriaList(List<T> ^CriterionList);
};

generic <typename Q, typename T>
public ref class IUseInterface : iTest<T>
{
public:
   virtual void AddCriteriaList(List<T> ^CriterionList)
   {
   }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号