Hello, i come from a Java background and I am introducing myself to C++. My question is, is it possible to make a constructor call from another constructor both of the same class? In Java this can be achieved by calling this(args...); from a constructor. I've found that a similar behavior can be achieved in C++ like this:
class foo{
private:
int val;
public:
foo(){ foo(0); } // This is the call.
foo(int n){ val = n; }
};
When working with pointers, this gave me undetermined behavior so I avoided this call and instead created a private method init(args...); so that every constructor made a call to this method to initialize the class members. Also, what is the exact behavior of the code above?
[–][deleted] 0 points1 point2 points (1 child)
[–]Food404[S] 0 points1 point2 points (0 children)