How can I initialize C++ object member variables in the constructor?
问题 I've got a class that has a couple of objects as member variables. I don't want the constructors for these members to be called when declared, so I'm trying to hang onto a pointer to the object explicitly. I have no idea what I'm doing. o_O On StackOverflow, I seem to be able to find other examples of object member variables, but usually the constructor is called immediately, like this: class MyClass { public: MyClass(int n); private: AnotherClass another(100); // this constructs AnotherClass