When overloading constructors, is it possible to have a non-default constructor call the default constructor, so that I am not copy-pasting the code from the default constructor into any later non-default constructors? OR what is the reason for not allowing this functionality?
Here's my code:
class Test{
private:
int age;
int createdAt;
public:
//Here is the defualt constructor.
Test(){
this->createdAt = 0;
};
//Non-default constructor calling default constructor.
Test(int age){
this->Test(); //Here, call default constructor.
this->age = age;
};
};
Do note that this code throws the compiler error "Invalid use of Test::Test", so I'm obviously doing something incorrect.
Thanks for your time!