Topics : Case studies | Consumer goods industry supply chain | Demand planning/management | Supply Chain Planning software | Supply chain software | Transportation Management Systems.
Give an example of friend classes in C++ and an example of when you would use one. In C++, the friend keyword can be applied to either a function or a class. A friend function or friend class has access to the private members of the class in which the declaration occurs. There are programmers who think that this feature violates the principles of object oriented programming because it allows a class to operate on another classâs private members.
In C++, I have a base class A, a sub class B. Both have the virtual method Visit. I would like to redefine 'Visit' in B, but B need to access the 'Visit' function of each A (and all subclass to). I have something like that, but it tell me that B cannot access the protected member of A! But B is a A too :-P. So, what can I do? class A { protected: virtual Visit(...); } class B : public class A { protected: vector<A*> childs; Visit(...); } B::Visit(...) { foreach(A* a in childs) { a->Visit(...); } } Thx