p*l
2 楼
struct A{
int *a;
A() {
a = new int;
*a = 5;
cout << "default construct is called" << endl;
}
A(const A& a) {
cout <}
A(A&& a){
cout << "move consturct is called" << endl ;
}
A& operator=(const A & a)
{
cout << "assignment " << endl ;
return *this;
}
~A()
{
cout << "release A" << endl ;
}
};
A getA() {
A a;
return a;
};
void main()
{
A a = getA();
cout << *(a.a)<< endl;
}
int *a;
A() {
a = new int;
*a = 5;
cout << "default construct is called" << endl;
}
A(const A& a) {
cout <}
A(A&& a){
cout << "move consturct is called" << endl ;
}
A& operator=(const A & a)
{
cout << "assignment " << endl ;
return *this;
}
~A()
{
cout << "release A" << endl ;
}
};
A getA() {
A a;
return a;
};
void main()
{
A a = getA();
cout << *(a.a)<< endl;
}
h*0
3 楼
等收到再定也不迟!我妈第四天护照就到手了!
j*w
4 楼
default construct is called
5
release A
看这里有在线执行结果:
https://codidate.com/code/sandbox?s=pkc5tq8s9q
5
release A
看这里有在线执行结果:
https://codidate.com/code/sandbox?s=pkc5tq8s9q
p*l
5 楼
发现不同编译系统,输出结果不一样
vc里面 输出还包括 "move consturct is called“
【在 j*****w 的大作中提到】
: default construct is called
: 5
: release A
: 看这里有在线执行结果:
: https://codidate.com/code/sandbox?s=pkc5tq8s9q
vc里面 输出还包括 "move consturct is called“
【在 j*****w 的大作中提到】
: default construct is called
: 5
: release A
: 看这里有在线执行结果:
: https://codidate.com/code/sandbox?s=pkc5tq8s9q
p*l
7 楼
多谢
【在 r*****z 的大作中提到】
: https://en.cppreference.com/w/cpp/language/copy_elision
【在 r*****z 的大作中提到】
: https://en.cppreference.com/w/cpp/language/copy_elision
相关阅读
程序员专用的记事本应用 Quiver Promotion ($1.99, TwoDollar T (转载)今晚收获很大魏老师原来是金融界的啊。好虫老魏你们这俩SB就不能合作么?如何证明goodbug是谁呢?spring boot sample project..神器阿彻底变成泼皮牛二软软的hololens啥时候能买dev kit啊?SP4做开发本有点坑,报告一下sun 的倒掉老魏我再问你国产软件为啥这么流氓zhaoce,请问vert.x能代替spring么?其实就是两党党争我戒网去了刚刚把我的Glock擦了一下,睡觉去喽phd码工感觉是完全不同的一个档次每个人为自己的言行负责,你既然敢说为啥这么怕人看?Internet of Thingsvert.x 3.1 视频 be reactive on the JVM but not only in Java by Clement Escoffier/Paulo Lopes