"Guriks" <ms*******@gmail.com> wrote in message
news:b4*************************@posting.google.co m...
HI,
When can i use aggregation and composition. I mean
Class A{
};
Class B{
private:
A a;
A* a;
}
In the abovecode. When can i use A a and A* a?
You should use a direct data member ( A a ), unless
there is a good reason to use a pointer (e.g. the
member is not always present, or is polymorphic,
or you want to implement a special C++ idiom such
as the 'pimpl'/implementation hiding).
When a pointer/indirection is needed, not that in
most cases a smart pointer (std::auto_ptr<A> or other)
will be preferred to a naked pointer (A*).
This helps ensure proper resource management.
hth,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <>
http://www.brainbench.com