let's say i have a class
class MyClass { public: AnotherClass myObject; };
My problem is that I want to initialize myObject with arguments to the constructor, exactly if I would declare it on the stack during the function
AnotherClass myObject(1, 2, 3);
but I want to do this for a class member in the constructor:
MyClass::MyClass() { myObject = ...? ... }
The problem is what exactly. If I declare a member of a class that has a constructor, will C ++ call the default constructor? How can I declare a variable in a class definition, but initialize it in the constructor?
Thanks for any answers!
source share