Friend's class and all his descendants

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

I tried with:

class E {

    friend class A;

    ...

};

But that does not work.

thanks

+3
source share
1 answer

You can put protected access functions in and have A be a friend of E. Thus, all derived classes of A can access the elements of E through access functions.

+17
source

Source: https://habr.com/ru/post/1719088/


All Articles