Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: private mem...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 45825 of 47032
Post > Topic >>

Re: private member variables

by James Kanze <james.kanze@[EMAIL PROTECTED] > May 9, 2008 at 08:07 AM

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
 




 6 Posts in Topic:
private member variables
wiskey5alpha <wiskey5A  2008-05-09 07:50:48 
Re: private member variables
James Kanze <james.kan  2008-05-09 08:07:07 
Re: private member variables
"3DCoderGuy" &l  2008-05-09 15:35:24 
Re: private member variables
"Jim Langston"   2008-05-09 09:00:57 
Re: private member variables
wiskey5alpha <wiskey5A  2008-05-09 10:15:03 
Re: private member variables
mlimber <mlimber@[EMAI  2008-05-09 10:35:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:17:54 CDT 2008.