class x { int a; int b = 7; // default member initializer int c; public: x() {} x(int a_, int c_) : a(a_), c(c_) {} x(int a_, int b_, int c_) : a(a_), b(b_), c (c_) {} // overrides default member initializer void print() const { cout << a << ' ' << b << ' ' << c << endl;} };
int main() { x obj1a; obj1a.print(); x obj1b(); // looks like a prototype x obj1c{}; // OK in C++11 obj1c.print();
x obj2(6,8); obj2.print();
x obj3a(1,2,3); obj3a.print(); x obj3b{5,6,7}; obj3b.print(); }
********* OUTPUT *********
4309728 7 4309822 // first and third values are random -2 7 1946580061 // first and third values are random 6 7 8 1 2 3 5 6 7