#include <iostream>
#include <string>
class Data
{
private:
int day, month, year;
public:
Data() : Data(0,0,0) {};
Data(int d, int m, int y) : day(d) , month(m), year(y) {}
void print() { std::cout << day << " " << month << " "<< year << std::endl; }
};
int main()
{
Data a;
a.print(); //ok - output: 0,0,0 and no compiler errors
}
A constructor does not have a returning value, and a constructor is called when an object is created, meaning the data can be initialized, so when I call a constructor from another constructor, is this completely valid?
I've also noticed that Data() { Data(0,0,0); };
does NOT initialize the current class data members.
Why is it that Data() : Data(0,0,0) {};
works and Data() { Data(0,0,0); };
does not?