I have an object... MyObject
it has a constructor MyObject::MyObject(string objName){ }
Suppose I need to use this object, within another class....
class OtherClass
{
MyObject obj1;
MyObject obj2;
}
This will give me an error, because its wanting it to look like...
class OtherClass
{
MyObject obj1("first name");
MyObject obj2("second name");
}
However, I wont know what first name, and second name are until later in the program
I could do this.....
class OtherClass
{
MyObject* obj1;
MyObject* obj2;
}
... then later on ....
OtherClass otherClass; otherClass.obj1 = new MyObject("first name"); etc.....
But I would really like to have the actual object, and not a ptr to an object.
Is it possible, or am I forced to use pointers.
Thanks.