Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dear All

I have an interface which is in C#,

public interface IMyInterface
{
string Properties { get;}
}


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'    


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
Posted
Updated 7-Feb-11 19:25pm
v2

1 solution

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
 
Share this answer
 
v4
Comments
Sandeep Mewara 8-Feb-11 1:42am    
Nice! kind of...'Loading...' :)
Sergey Alexandrovich Kryukov 8-Feb-11 1:49am    
Excuse me, Sandeep, what's 'Loading...'?
Sandeep Mewara 8-Feb-11 3:31am    
You wrote 'Editing'... and probably was updating your answer. At that time, I put that comment. :)
Radhakrishnan G. 8-Feb-11 3:29am    
Actually it is not String some other collection of properties

class PropertyCollector
{
IPropertyProvider _provider;

object this[string name]
{
get{ return _provider.GetValue( name);}
set{ _provider.SetValue( name, value);}
}

}
Sergey Alexandrovich Kryukov 8-Feb-11 18:42pm    
I refer to this line:
virtual String^ get() { return "";}
Are you saying "String" above is not System::String?! At least your naming is design to mislead then.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900