Question on class private member

B

Bit byte

I have a class that has a privat member which is a struct which holds
several other structs. I have 2 questions, should I declared my member
variable that stores the other structs as :

A).

struct one_way_ {
struct A a;
struct B b ;
//... etc
struct N n;
} m_priv ;


OR
====

B).

struct another_way_ {
struct A *a;
struct B *b ;
//... etc
struct N *n;
} m_priv ;



1). Are there any advantages of one over the other ?

2). If I want to write methods that populate the class (containg
m_priv), is it better to use structure defined in A or B? (Assume that
the structures in m_priv themselves are nested and contain pointers.
 
G

Guest

I think which is the better depends on what you are gong to do. The
first one 's fault is the structs held in it MUST have complete copy
construct and assignment operator , and because of lots of implicit
operating it's effect is low. However, the other's is high. but you
have to pay more attention to deleting it's member variables.
 
A

Alf P. Steinbach

* 海风:
I think which is the better depends on what you are gong to do. The
first one 's fault is the structs held in it MUST have complete copy
construct and assignment operator , and because of lots of implicit
operating it's effect is low. However, the other's is high. but you
have to pay more attention to deleting it's member variables.

To what does the above refer?

Please learn to quote.

Usenet isn't a web forum, Usenet is not Google Groups.
 
B

Bo Persson

Bit byte said:
I have a class that has a privat member which is a struct which holds
several other structs. I have 2 questions, should I declared my
member variable that stores the other structs as :

A).

struct one_way_ {
struct A a;
struct B b ;
//... etc
struct N n;
} m_priv ;


OR
====

B).

struct another_way_ {
struct A *a;
struct B *b ;
//... etc
struct N *n;
} m_priv ;



1). Are there any advantages of one over the other ?

2). If I want to write methods that populate the class (containg
m_priv), is it better to use structure defined in A or B? (Assume
that the structures in m_priv themselves are nested and contain
pointers.

It all depends on what you mean by "is better". :)

Generally, you should avoid pointers, unless you find out that you
specifically need them. Do you think that is the case here?


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top