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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object lifetime

Status
Not open for further replies.

minoad

Programmer
Mar 28, 2001
138
US
It seems that as with the arrays, i am also having issues with object lifetime. I would like the constructor of class1 to create 60 instances of class2. This is fine as long as i only refrence those objects from within class2.cpp. Is it possible to create an instance of an object and make it available to my code project wide?
 
make sure you include the class2 header file in class 1.
Code:
//in class2's header file:

class1 * instances;

//in class2's constructor:
instances= new class1 [60];
//initialize them as you want.

now, while you're implementing class2, you will only have access to public vars/functions of class1 (unless you use inheritence).

you should make getters/setters for the var instances. then you should be able to access all public functions of instances wherever the instance of class2 is in scope..

is this waht you were asking? if not, i'm not clear on your question! plz be more specific!

hope this helps!
 
well.. a friend function is usually considered bad design in OO...
 
Declare class2 variables as globals - outside class1, or in your case make class1 global
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top