Constructor issue
Posted
by
laura
on Stack Overflow
See other posts from Stack Overflow
or by laura
Published on 2012-11-06T17:23:17Z
Indexed on
2012/12/06
23:04 UTC
Read the original article
Hit count: 202
c++
This is the code that I worked on and I don't understand what it's happening on constructor Package obj2(); On output are displayed 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);
}
© Stack Overflow or respective owner