Class Interactions



































Contains - by value.



class X

{

private Y itsY;

};



!! indicates that X and Y have
identical lifetimes.

When X is destroyed, Y will be destroyed too



Uses.



class X

{

public: void F(const Y&);

};





Y is used within the source code
of class X.

Have different lifeline. Y may outlive X.



Contains - by reference.



class X

{

private:

Y* itsY;

};



This is used to indicate that X
and Y have dissimilar lifetimes.

Y may outlive X.



Inheritance.



Class Y:X


{}



This indicates that Y is a public

base class of X. have same lifetime.


 



Invoking a member function.



void X::F(Y& theY)

{

P p;

V v = theY.M(p);

}



 



Using a container class.



class X

{

private:

Set<Y*> itsYs;

};



Contains array or so.


Can have different lifetimes