【问题标题】:c++/cli Explicit implementation of interface overridesc++/cli 接口覆盖的显式实现
【发布时间】:2012-07-19 15:05:02
【问题描述】:

我有两个接口:

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 项目中使用这些接口。那么,如何在 c++/cli 中实现呢?

提前致谢。

【问题讨论】:

    标签: c++-cli


    【解决方案1】:

    我自己解决了。应该是:

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

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 2011-04-11
      相关资源
      最近更新 更多