A
Amit Gupta
How do I do it (either by friend or by any other hack).
I have three class, I am just writing derivation below:
class A{}
class B{}
class C : public class B{}
class D: public class B ()
Now, class B would like to have access to A's private memebers (lets
say I make B a friend of A)
Now I also want C,D to have equal access to private members of class
A. I know, with friends definition, it is not possible, derived
classes dont inherit friendship of base class. Is there any other way
I can do this?
My flexibilities are:
I don't necessarily need to make C/D derived classes of B. I can do
something else too (what something else, I dont know but all I am
saying is, it is not REQUIRED to make C/D derived from B)
I don't want to make changes to A, once I write A, and write minimal
association of B to A (like B is friend of A), I want some way for C/
D, to access parts of B.
Now, the actual problem I have is, A is my design class
B is the first unit-test class I wrote for A, and I added B as friend
of A in design of A.
Few days later, I realized I need a new unit test for A, and therefore
I need a class C/D..but then I had to change A to make C/D friend of
A.
Another problem is, C/D are unit-tests that access multiplt design
classes. I could make all of design classes friend of single class B,
but then I dont want to change all those design classes to add C/D/E/
F.. as friend.
Thoughts, brain-storming is appreciated.
Thanks
I have three class, I am just writing derivation below:
class A{}
class B{}
class C : public class B{}
class D: public class B ()
Now, class B would like to have access to A's private memebers (lets
say I make B a friend of A)
Now I also want C,D to have equal access to private members of class
A. I know, with friends definition, it is not possible, derived
classes dont inherit friendship of base class. Is there any other way
I can do this?
My flexibilities are:
I don't necessarily need to make C/D derived classes of B. I can do
something else too (what something else, I dont know but all I am
saying is, it is not REQUIRED to make C/D derived from B)
I don't want to make changes to A, once I write A, and write minimal
association of B to A (like B is friend of A), I want some way for C/
D, to access parts of B.
Now, the actual problem I have is, A is my design class
B is the first unit-test class I wrote for A, and I added B as friend
of A in design of A.
Few days later, I realized I need a new unit test for A, and therefore
I need a class C/D..but then I had to change A to make C/D friend of
A.
Another problem is, C/D are unit-tests that access multiplt design
classes. I could make all of design classes friend of single class B,
but then I dont want to change all those design classes to add C/D/E/
F.. as friend.
Thoughts, brain-storming is appreciated.
Thanks