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 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?
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.