It's so messy w/o the "friend" relationship. Does anyone know why it was not supported in C#. It's almost about as bad as it doesn't support the inheritance hierarchy and method reference (calling tree) browsing that is supported in C++. I don't know how some could write a large scale object-oriented application w/o those. If you have overcome these limitations in C#, please share your thoughts and ideas. Thanks!
Can you give me some examples of C++ that C# cannot (As stated above)? I've been using C# for a while now, and the only problems I've ran into involve things that could possibly make the code unstable. And there has always been an alternate, safer, way of doing things. But perhaps I'm not quite understanding the question. Just give me some code samples of what you are talking about.
I am trying to write a class which no one can derive apart from my classes. Something like Code: class Usable; // cannot be derived apart from my known classes class Usable_lock { friend class Usable; private: Usable_lock() {} Usable_lock(const Usable_lock&) {} }; class Usable : public virtual Usable_lock { // ... public: Usable(); Usable(char*); // ... }; Usable a; class DD : public Usable { }; DD dd; // error: DD::DD() cannot access // Usable_lock::Usable_lock(): private member I am sure this is possible in C# but I am not sure how. Can you help me in this regard.
You can use the "internal" keyword. In C#, "internal" equates to allowing access to all classes that are in the same assembly as this class. There is no 1:1 support for "friend" but "internal" should be all you need. VisualStudio (and most C# editors) have code rollup and #region support, just use that to cut down your lines of code if your doing a lot of classes in it. So just declare your classes with "internal" perpended to it and everything should be peachy.
Yes thats a good option. Infact the support of all the access specifiers is logistic public Access is not restricted. protected Access is limited to the containing class or types derived from the containing class. internal Access is limited to the current assembly. protected internal Access is limited to the current assembly or types derived from the containing class. private Access is limited to the containing type.