why should the parameter in copy construction be a reference
if not, it will lead to an endless loop!!!
# include<iostream>
using namespace std;
class A
{
public:
int var; A():var(){} A(A &a){this->var = a.var;cout << "copy\n";} void operator=(A b){cout << "assign\n";} A func(A a){return a;}
//A func(A &a){ return a; } ~A(){cout << "destroy\n";}
}; int main()
{
A a, b, c;
b.var = ;
a = b;
cout << "\n";
c = a.func(b);
system("pause");
}
update: 1) class a = b; 2) a=c;
1) will call copy constructor, because a havent be constructed;
2) will call assignemnt constructor, because a has it's mem room, we should just modify it's value
why should the parameter in copy construction be a reference的更多相关文章
- C++ Copy Elision
故事得从 copy/move constructor 说起: The default constructor (12.1), copy constructor and copy assignment ...
- Copy Control settings
Copy Control settings Skip to end of metadata Created by Rajesh Banka, last modified by Jyoti ...
- C++ std::deque
std::deque template < class T, class Alloc = allocator > class deque; Double ended queue deque ...
- 词频统计_输入到文件_update
/* 输入文件见337.in.txt 输出文件见338.out.txt */ #include <iostream> #include <cctype> #include &l ...
- algorithm之改变序列算法--待解决
简述:改变序列算法,参见http://www.cplusplus.com/reference/algorithm/?kw=algorithm 待解决问题:iterator_traits.std::mo ...
- 《Effective Modern C++》翻译--简单介绍
北京时间2016年1月9日10:31:06.正式開始翻译.水平有限,各位看官若有觉得不妥之处,请批评指正. 之前已经有人翻译了前几个条目,有些借鉴出处:http://www.cnblogs.com/m ...
- C++ Core Guidelines
C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...
- 如果返回结构体类型变量(named return value optimisation,NRVO)
貌似这是一个非常愚蠢的问题,因为对于具有良好素质的程序员而言,在C中函数返回类型为结构体类型是不是有点不合格,干嘛不用指针做传入传出呢? 测试环境:Linux IOS 3.2.0-45-generic ...
- <Effective C++>读书摘要--Templates and Generic Programming<一>
1.The initial motivation for C++ templates was straightforward: to make it possible to create type-s ...
随机推荐
- 自学python 2.
1.T or F 1>1 or 3<4 or 4>5 and 2>1 and 9>8 or 7<6 t not 2>1 and 3<4 or 4> ...
- SQL Server进阶(十一)临时表、表变量
临时表 本地临时表 适合开销昂贵 结果集是个非常小的集合 -- Local Temporary Tables IF OBJECT_ID('tempdb.dbo.#MyOrderTotalsByYe ...
- Python 生成requirement 使用requirements.txt安装类库
快速生成requirement.txt的安装文件 (CenterDesigner) xinghe@xinghe:~/PycharmProjects/CenterDesigner$ pip freeze ...
- markdown & mathjax 初学笔记 latex
stackedit 1.标题大小和# # 数量代表标题大小,越多越小 2.* 斜体 * 3.** 粗体 ** 4.*** 又粗又斜 *** PS:符号紧贴 5. 分隔符 - - - 三个减号 PS: ...
- 如何解决无法成功git commit 和git push
如何解决无法成功git commit 和git push 20155324王鸣宇.20155314刘子健 git add . 成功了 但是git commit无法实现. 我先尝试了卸载git 重新下载 ...
- html5 area实例
真实页面效果:就是一张图 html代码: <!DOCTYPE HTML> <html> <style> body{ padding:0px; margin:0px; ...
- Access数据库SQL注入(Access SQL Injection)
一.Microsoft Office Access数据库手工注入语句 1.参数后面加 ’ .and 1=1.and 1=2看返回状态判断是否存在注入点 2.参数后面加 and exists(sel ...
- node里面的buffer理解
node提供了专门读写文件的模块,文件内容都是2进制存放在内存中的 node读取文件的结果都是16进制,那么你要学会进制转换,二进制0b开头 ,八进制0开头,十六进制0x 基础知识: 1字节=8bit ...
- C 捕获 lua 异常错误
参考文章https://blog.codingnow.com/2015/05/lua_c_api.html , , )) { printf("file=%s, func=%s, line=% ...
- retrofit动态代理
https://blog.csdn.net/dalong3976/article/details/83479816