views:

109

answers:

1

Hello, 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

+12  A: 

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.

camh
+1, exactly what i was thinking
That's not exactly what I wanted, but it's ok :) thank you
tunnuz