Home > Back-end > A friend derived class reloading function
A friend derived class reloading function
Time:09-21
Class A { Friend class B; Protected: Int m_iA=0; }
Class B { Protected: A, m_a. Virtual void func () {m_a. M_iA=1; } }
Class C: class B { Virtual void func () {m_a. M_iA=2; } }
In the above relations, inheritance from B, C C overloaded function func, C func function overloading in the hope of its base class B member variables m_a do some different operations, But for A friendly against A B yuan relationship cannot be C inheritance, so the actual operation is not feasible,
Question: what can you do to solve this problem? Hope to have more professional,
CodePudding user response:
Need to revise the B:
#include
Class A { Friend class B; Protected: Int m_iA; };
Class B { Protected: A, m_a. Virtual void func (int I) {m_a. M_iA=I; } Public: Void the print () {printf (" % d \ n ", m_a m_iA); }; };
Class C: public B { Public: Void test () {func (2); Print (); } };