hey guys! I have a few questions that came arcoss as I learn C++.
this is going to be a batch of questions so please be patient, help will be appritiated !
Delegation:
the idea of delegation is a but abscure for me.
as far as I understand - delegation is giving an object the functionality of other object, because inheritance is not right enough for that task.
(correct me if I wrong please)
delegation is used in many ways, but 2 main ways of doing it is by:
1) containing an object in another object , and call the contained-object-methods to the conatining-object
2) by using pointers to function. this require a small explanation - do I create a pointer to a member function and set it to be as a member in other object?
Frienship:
why can't this code be compiled?
it's complaining that A::x is private - but the frienship should give B excess to all of A members, right?Code:#include <iostream> class A{ private: friend class B; int x; public: A(int r) :x(r) {}; }; class B{ public: void print (int y){std::cout<<y;} }; int main (void){ A a(6); B b; b.print(a.x); return 0; }