【问题标题】:C++ CLI Syntax: Generic method?C++ CLI 语法:通用方法?
【发布时间】:2011-09-04 06:54:35
【问题描述】:

任何人都可以提供帮助`

我需要一个在 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会检查一个指向接口的点是否已经设置,然后在接口中调用这个方法,就像事件处理程序一样,所以参数必须匹配)。

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

【问题讨论】:

    标签: c++-cli


    【解决方案1】:

    目前还不清楚您在寻找什么。必须使用 where 关键字声明约束:

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

    【讨论】:

    • 这对我有帮助。我只是没有正确获得 hwole 声明。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多