Thursday, September 17, 2009

c++ Insulation (II)

So did you get the answer?

  • HasA/HoldsA: if you embedd a pointer or a reference to an object you don't need to know the physical layout of that object. There is no dependency apart from the name of the object itself. So you can make a forward declaration. No more dependency, no more cats to follow. I like cats; I don't like having them come to me just for milk ;-). In the below code fragment, you don't need to include any .h file for including the declaration of B class. no dependecy at all.
  
class B;
class A {
B * pBobj;
B & rBobj;
};

No comments:

Post a Comment