On May 9, 4:50 pm, wiskey5alpha <wiskey5Al...@[EMAIL PROTECTED]
> wrote:
> I have a design question.
> assuming we have
> class Bar {...} // body omitted for clarity
> class Foo
> {
> // should Bar be implemented as a pointer or not here ?
> Bar *m_bar; // OPTION 1
> // or
> Bar m_bar; // OPTION 2
It depends somewhat on Bar, and what you're doing with it. In
general, use a value if you can, a pointer if you have to.
> ... // body omitted for clarity
> Foo::Foo()
> // OPTION 1
> m_bar =3D new Bar;
> m_bar.setID(1);
That would be m_bar->setID( 1 ) ;
> // or
> m_bar.setID(1);
> I have seen both of these methods used, so I am wondering if
> there is any memory or speed differences between the two ?
Probably not enough to worry about. On the other hand, using a
member object is a lot surer and more reliable.
--
James Kanze (GABI Software) email:james.kanze@[EMAIL PROTECTED]
en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34


|