Hello.
I was wondering how to pass parameters to constructors (which require them) of class object members of another class?
For example, say I have the following code:
Would I just call the classA object's constructor from classB's constructor, and pass the integer there? But I think I remember reading somewhere that any class object you make a member of another class causes that class's constructor to be automatically called (only without parameters, I'm sure). But how does it handle cases where the class constructor has a required parameter?Code:class classA { public: classA(int i) { num = i; } private: int num; }; class classB { public: classB(); private: classA myObject; //this is the line I'm talking about; //how would I pass an integer to the //constructor of classA from the declaration //of classB, when "myObject" is an object of //classA? };
Note that both classes are only hypothetical, and the real class I'm writing is making an object of a Qt class which happens to have a constructor with a required parameter.
Thanks in advance.