constructor and deconstructor
#include <iostream>
#include<string>
#include<vector>
using namespace std;
class B
{
private:
int data;
public:
B()
{
cout << "default constructor" << endl;
}
~B()
{
cout << "destructed" << endl;
}
B( int i ) : data(i)
{
cout << "constructor by parameter" << data <<endl;
}
};
B Play ( B b)
{
return b;
}
int main()
{
B temp = Play(5);// Play call the constructor(with parameter),initialize the parameter data,make data=5;
return 0; // temp and Play object ,call the defaule deconstructor;
}
The result:
constructor by parameter 5
destructed
destructed