c++/cli Explicit implementation of interface overrides

徘徊边缘 提交于 2019-12-12 16:07:18

问题


I have two interfaces:

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

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

In C# I can explicitly implement like this:

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

Somehow I have to use these interfaces in a c++/cli project. So, how can I implement this in c++/cli?

Thanks in advance.


回答1:


I solved it myself. It should be:

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 { }
     }
 }


来源:https://stackoverflow.com/questions/11536808/c-cli-explicit-implementation-of-interface-overrides

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!