Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Several instances of a class? 1

Status
Not open for further replies.

aaadetos

Programmer
Nov 21, 2004
54
US
Is there any disadvantage to instantiating a class object several times to point to the same variable when if the variable is used in deiiferent source files? What about if the same class object points to different member variables within a project?
 
I'm sorry for being vague.

I have a project with a couple of source files. It's a dialog-based application. The source code needs to interact with some of the variables on my dialog box, which are user-determined.

I'm wondering if creating several instances of my class object (say up to 6 times), would affect my application in any way.

E.g.
Code:
int j;
COxymoron MyClass;
MyClass.m_iBiscuits = j;

If say the object "MyClass" is instantiated say 6 times, within different source files in my project, will this adversely affect my application? Or would I be safer to define different object names for each instance of class COxymoron?

Thanks.
 
It doesn't matter what you CALL the object. If there's six instances, there's six instances. However, if you have only one instance that you want to use in your dialog, and want all other classes to point to that instance, then just use a pointer of your class type in the other classes and set the pointer equal to the address of the first one. So if you declare this:

Code:
Myclass m_class;

in your dialog class, then in a different class,

Code:
Myclass* m_pClass

this is better. If an object of type MyClass is 64 bytes, a pointer of type MyClass is only 4 bytes.

I hope I'm understanding you correctly. If not, please post again if you don't understand what I'm saying, or if I don't understand what you're saying.

BlackDice

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top