gpt4 book ai didi

c++-cli - C++ CLI 语法 : Generic method?

转载 作者:行者123 更新时间:2023-12-01 11:05:39 25 4
gpt4 key购买 nike

任何人都可以提供帮助`

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

我现在尝试以下操作:

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

遗憾的是它不起作用。该方法必须接受 K 和 U,C# 定义为:

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

(是的,方法不同 - OnUpdate 会检查接口(interface)的点是否已设置,然后在接口(interface)中调用此方法,就像事件处理程序一样,因此参数必须匹配)。

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

最佳答案

您要查找的内容并不清楚。必须使用 where 关键字声明约束:

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

关于c++-cli - C++ CLI 语法 : Generic method?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6167621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com