Possible duplicate:
The default constructor with empty brackets
This is the code I was working on, and I donβt understand that this is happening in the Package obj2 () constructor; The output displays only the values ββ4 (package obj1 (4)) and 2 (package obj3 (2))
#include <iostream> using namespace std; class Package { private: int value; public: Package() { cout<<"constructor #1"<<endl; value = 7; cout << value << endl; } Package(int v) { cout<<"constructor #2"<<endl; value = v; cout << value << endl; } ~Package() { cout<<"destructor"<<endl; cout << value << endl; } }; int main() { Package obj1(4); Package obj2(); Package obj3(2); }
laura source share