#include "stdafx.h"
#include <iostream>
class A
{
public:
A() { std::cout << "Constructor" << std::endl; }
A(const A&) { std::cout << "Copy Constructor" << std::endl; }
~A() {}
};
static A getA()
{
A a;
return a;
}
int main()
{
A a = getA();
return 0;
}
#include "stdafx.h"
#include <iostream>
class A
{
public:
A() { std::cout << "Constructor" << std::endl; }
A(const A&) { std::cout << "Copy Constructor" << std::endl; }
A(const A&&) { std::cout << "Move Constructor" << std::endl; }
~A() {}
};
static A getA()
{
A a;
return a;
}
int main()
{
A a = getA();
return 0;
}
#include "stdafx.h"
#include <iostream>
#include <vector>
class B
{
public:
B() {}
B(const B&) { std::cout << "B Constructor" << std::endl; }
};
class A
{
public:
A(): m_b(new B()) { std::cout << "A Constructor" << std::endl; }
A(const A& src) :
m_b(new B(*(src.m_b)))
{
std::cout << "A Copy Constructor" << std::endl;
}
A(A&& src) :
m_b(src.m_b)
{
src.m_b = nullptr;
std::cout << "A Move Constructor" << std::endl;
}
~A() { delete m_b; }
private:
B* m_b;
};
static A getA()
{
A a;
std::cout << "================================================" << std::endl;
return a;
}
int main()
{
A a = getA();
std::cout << "================================================" << std::endl;
A a1(a);
return 0;
}
#include "stdafx.h"
#include <iostream>
#include <vector>
class B
{
public:
B() {}
B(const B&) { std::cout << "B Constructor" << std::endl; }
};
class A
{
public:
A(): m_b(new B()) { std::cout << "A Constructor" << std::endl; }
A(const A& src) :
m_b(new B(*(src.m_b)))
{
std::cout << "A Copy Constructor" << std::endl;
}
A(A&& src) :
m_b(src.m_b)
{
src.m_b = nullptr;
std::cout << "A Move Constructor" << std::endl;
}
~A() { delete m_b; }
private:
B* m_b;
};
static A getA()
{
A a;
std::cout << "================================================" << std::endl;
return a;
}
int main()
{
A a = getA();
std::cout << "================================================" << std::endl;
A a1(a);
std::cout << "================================================" << std::endl;
A a2(std::move(a1));
return 0;
}
#include "stdafx.h"
#include <iostream>
#include <vector>
class B
{
public:
B() {}
B(const B&) { std::cout << "B Constructor" << std::endl; }
};
class A
{
public:
A(): m_b(new B()) { std::cout << "A Constructor" << std::endl; }
A(const A& src) :
m_b(new B(*(src.m_b)))
{
std::cout << "A Copy Constructor" << std::endl;
}
A(A&& src) :
m_b(src.m_b)
{
src.m_b = nullptr;
std::cout << "A Move Constructor" << std::endl;
}
A& operator=(const A& src)
{
if (this == &src)
return *this;
m_b = new B(*(src.m_b));
std::cout << "operator=(const A& src)" << std::endl;
return *this;
}
A& operator=(A&& src)
{
if (this == &src)
return *this;
m_b = src.m_b;
src.m_b = nullptr;
std::cout << "operator=(const A&& src)" << std::endl;
return *this;
}
~A() { delete m_b; }
private:
B* m_b;
};
static A getA()
{
A a;
std::cout << "================================================" << std::endl;
return a;
}
int main()
{
A a = getA();//移动构造
std::cout << "================================================" << std::endl;
A a1(a);//拷贝构造
std::cout << "================================================" << std::endl;
A a2(std::move(a1));//移动构造
std::cout << "================================================" << std::endl;
a2 = getA();//移动赋值
std::cout << "================================================" << std::endl;
a2 = a1;//拷贝赋值
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有