由于基类为内部类,因此无法在C ++/CLI中实现接口 [英] Unable to implement Interface in C++/CLI due to an internal class in base

查看:59
本文介绍了由于基类为内部类,因此无法在C ++/CLI中实现接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人

我有一个C#接口,

Dear All

I have an interface which is in C#,

public interface IMyInterface
{
string Properties { get;}
}



在C ++/CLI中,我有一个用户控件,实现了接口



In C++/CLI I have a usercontrol, implemented the interface

public ref class MyUserControl: public UserControl, IMyInterface
{
// overriding IMyInterface
public:
    property String^ Properties
    {
       virtual String^ get() { return "";}
    }

// Also tried
// property String^ IMyInterface::Properties
//{
//    virtual String^ get() { return "";}
//}
}





Error   1   error C2248: ''System::Windows::Forms::Control::Properties'' : cannot access private class declared in class ''System::Windows::Forms::Control''    



可能由于Control中有一些内部类,因此有任何方法可以克服此问题
但是同样可以在覆盖属性的同时使用scope(IMyterface.Properties)在C#中完美地工作.

谢谢



May due to some internal class in Control, any way to overcome this
But same this is working perfect in C# by using the scope(IMyterface.Properties) while overriding the property.

Thanks

推荐答案

只需重命名Properties;使用其他名称,那么它将起作用.另外,请不要使用复数形式(这只是一个字符串,对;有很好的命名规则).巧合的是,此名称与System.Windows.Forms.Control中的私有类发生冲突. C#的可见性/范围略有不同.

以接口名称(IMyInterface::)限定的已实现接口函数的第二种形式更好;它将对类实例的用户隐藏对接口部分的访问.

顺便说一句,不要写"",而要写String::Empty.

—SA
Just rename Properties; use some other name, then it will work. Also, don''t use in plural (this is only one string, right; there are good naming rules). By coincidence this name clashed with a private class inside System.Windows.Forms.Control. C# has slightly different approach to visibility/scope.

Second form of implemented interface function qualified with interface name (IMyInterface::) is better; it will hide access to interface part from the user of the class instance.

By the way, do not write "", write String::Empty instead.

—SA


这篇关于由于基类为内部类,因此无法在C ++/CLI中实现接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆