开发者

C++ CLI Syntax: Generic method?

开发者 https://www.devze.com 2023-03-08 21:17 出处:网络
Anyonecan help` I need to have a generic method which in C++/CLI. I try the following at the moment: generic<K, ref class U>

Anyone can help`

I need to have a generic method which in C++/CLI.

I try the following at the moment:

generic<K, ref class U> 
void OnUpdate (
    K key,
    U update
);

Sadly it does not work. The method must 开发者_StackOverflow中文版accept K and U, and the C# definitions are:

void DataUpdate<K, U>(DataUpdate<K, U> update) where U : class;

(yes, the method is different - OnUpdate will check whether apoint to an interface has set, then call this method in the interface, like an event handler, so the parameters must match).

The generic syntax in C++/CLI eludes me. I have no problem defining K also to be a class.


It is not that clear exactly what you are looking for. Constraints must be declared with the where keyword:

generic<typename K, typename U> 
where U : ref class
void OnUpdate (K key, U update)
{
   // etc..
}
0

精彩评论

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