泛型类中可能有更多"where"约束吗?

more "where" constraints in generic class is possible?

本文关键字:where 约束 可能有 泛型类      更新时间:2023-10-16

我有一个接口(因为我想不出一种方法来为我从DB查询调用中检索到的内容设置属性),它是这样定义的,

interface class IData
{
public:
   void Set(int i);
   int Get();
};

我有一个像这样定义的泛型类

generic<typename T, typename U> where T:IsomeInterface public ref class MyClass{};

我想在上面的MyClass声明中添加"where U:IData",但我现在卡住了。

这和c#一样。这样的:

generic<typename T, typename U> 
    where T:IData
    where U:IData
public ref class MyClass { 
    };

. .等。