C++ cli C++;CLI语法:泛型方法?

C++ cli C++;CLI语法:泛型方法?,c++-cli,C++ Cli,任何人都可以帮忙` 我需要一个在C++/CLI中使用的通用方法 目前,我尝试以下方法: generic<K, ref class U> void OnUpdate ( K key, U update ); 通用 无效更新( K键, U更新 ); 可悲的是,它不起作用。该方法必须接受K和U,C#定义为: void DataUpdate<K, U>(DataUpdate<K, U> update) where U : class; void

任何人都可以帮忙`

我需要一个在C++/CLI中使用的通用方法

目前,我尝试以下方法:

generic<K, ref class U> 
void OnUpdate (
    K key,
    U update
);
通用
无效更新(
K键,
U更新
);
可悲的是,它不起作用。该方法必须接受K和U,C#定义为:

void DataUpdate<K, U>(DataUpdate<K, U> update) where U : class;
void DataUpdate(DataUpdate-update),其中U:class;
(是的,方法是不同的-OnUpdate将检查接口的apoint是否已设置,然后在接口中调用此方法,就像事件处理程序一样,因此参数必须匹配)


我无法理解C++/CLI中的通用语法。我可以将K定义为一个类。

你要找的东西还不太清楚。必须使用where关键字声明约束:

通用
其中U:ref类
无效OnUpdate(K键,U更新)
{
//等等。。
}

这对我很有帮助。我只是没有得到正确的hwole声明。
generic<typename K, typename U> 
where U : ref class
void OnUpdate (K key, U update)
{
   // etc..
}