gpt4 book ai didi

c++-cli - c++/cli 接口(interface)覆盖的显式实现

转载 作者:行者123 更新时间:2023-12-04 03:10:50 25 4
gpt4 key购买 nike

我有两个接口(interface):

public interface I1
{
A MyProperty { get; set; }
}

public interface I2 : I1
{
new B MyProperty { get; set; }
}

在 C# 中,我可以像这样显式地实现:

public class C : I1, I2
{
public B MyProperty { get; set; }
A I1.MyProperty { get; set; }
}

不知何故,我必须在 c++/cli 项目中使用这些接口(interface)。那么,如何在 c++/cli 中实现呢?

提前致谢。

最佳答案

我自己解决了。应该是:

public ref class C : I1, I2
{
public:
virtual property B^ MyProperty
{
B^ get() { ... }
void set(B^ value) { ... }
}

protected:
virtual property A^ DummyProperty
{
A^ get() = I1::MyProperty::get { return nullptr; }
void set(A^ value) = I1::MyProperty::set { }
}
}

关于c++-cli - c++/cli 接口(interface)覆盖的显式实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11536808/

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