Call constructor within constructor. How to?
How do i call a constructor of a class from another overloaded constructor?
Example:
Code:
class Stuff{
int a;
Stuff(int n=0) : a(n){
}
Stuff(Stuff& s) : Stuff(s.a){
}
};
My compiler (MSVC++6) states that Stuff(int) is not a member of Stuff if I try to call if from Stuff(Stuff&). This example is only to show what I'm trying to ask. But I'd like possibly to call other constructors when there's a reasonable set of variables. In Java we can use the this() operator.
I could create a initialization function to receive n arguments, being this function called by all constructors with different parameters, but that's not as efficient as calling directly the constructors for the class variables.
So I ask is there a way of calling the constructor?