How do i call a constructor of a class from another overloaded constructor?
Example:
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.Code:class Stuff{ int a; Stuff(int n=0) : a(n){ } Stuff(Stuff& s) : Stuff(s.a){ } };
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?



LinkBack URL
About LinkBacks



My badly expressed point was that I'd like you to show a better example of what you are trying to do, since I get the feeling that there might be a simpler answer.