473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Question on class private member

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.

Apr 2 '06 #1
3 1077
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.

Apr 2 '06 #2
* 海风:
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.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 2 '06 #3

"Bit byte" <fl**@flop.com> skrev i meddelandet
news:cI********************@bt.com...
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

Apr 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sean W. Quinn | last post by:
Hey folks, I have a question regarding file handling, and the preservation of class structure. I have a class (and I will post snippets of code later in the post) with both primitive data...
1
by: cppforlife | last post by:
I have a question about using 'has a' inheritance. I want to know how to extend class that had been used in another class. What i mean is if i have AddressBook class and its private member...
8
by: __PPS__ | last post by:
Hello everybody, today I had another quiz question "if class X is privately derived from base class Y what is the scope of the public, protected, private members of Y will be in class X" By...
7
by: Bob Morvay | last post by:
I am trying to determine how far I should go in encapsulating data. As I understand it, OO practices state to create private member variables and use these variables in your publicly accessible...
19
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works"...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
7
by: Matt | last post by:
I've asked this question to some developers that are much more experienced than I, and gotten different answers --- and I can't find anything about it in the documentation. Dim vs. Private as a...
14
by: Alexander Dong Back Kim | last post by:
Dear all, I used to use C++ programming language at all time but moved to C# and Java. Few days ago, I restarted studying about C++ with a very beginner's mind. I wrote a simple class and gcc...
4
by: BillG | last post by:
I have pondered this question often and have done it several ways but I am wondering what is the correct OO way to handle this. In my SQL Sever database I have the following tables for example, ...
8
by: anonymous | last post by:
I'm having some trouble understanding the meaning of visibility. <?php class foobar { private $key1 = "cat"; private $key2 = "apple"; protected $key3 = "book"; public $key4 = 42; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.