Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Friend class and all its descendants

suppose that I have a class A with several subclasses (B, C, and D). I need B C and D to access some protected members from a class E. Is it possible to make B, C and D friends of E in a single hit without having to list them all?

I have tried with:

class E {

    friend class A;

    ...

};

But this doesn't work.

Thank you

like image 327
tunnuz Avatar asked Dec 04 '22 14:12

tunnuz


1 Answers

You can put protected accessor functions in A, and have A be a friend of E. That way, all derived classes of A can access the members of E via the accessor functions.

like image 137
camh Avatar answered Dec 09 '22 15:12

camh