#include <iostream>
using namespace std;
class B
{
public:
B() { cout << "default constructor called." << endl;}
B(int i) : x(i) { cout << "parameter constructor called. " << i << endl;}
~B() { cout << "deconstructor called." << endl;}
void setX(int i) { x = i;}
int getX() const { return x;}
private:
int x;
};
B func(B b)
{
return b;
}
int main()
{
B temp = func(7);
}
$ cat main.cpp ; g++ -fno-elide-constructors main.cpp -o demo.exe; ./demo.exe
#include <iostream>
using namespace std;
class B
{
public:
B() { cout << "default ctor: " << this<< endl;}
B(int i) : x(i) { cout << "parameter ctor: " << this << endl;}
B(B const&){cout << "copy ctor " << this << endl;}
B & operator = (B const&){cout << "copy ctor " << this << endl;return *thi
s;}
~B() { cout << "dtor:" << this << endl;}
void setX(int i) { x = i;}
int getX() const { return x;}
private:
int x;
};
B func(B b)
{
return b;
}
int main()
{
B temp = func(7);
}
parameter ctor: 0x22ff0c
copy ctor 0x22ff08
copy ctor 0x22ff04
copy ctor 0x22ff00
dtor:0x22ff04
dtor:0x22ff08
dtor:0x22ff0c
dtor:0x22ff00
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。