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 ...
随机推荐
- SQL Server2012安装流程
今天手比较抽风,把原来的SQL Server给卸载了,卸载还卸了半天,真是…… 安装时找了好多教程,结果都不是很详细,然后准备自己摸索一下,把这个过程记录下来,供大家参考,如果有不当的地方,欢迎指正, ...
- PHP7 学习笔记(十一)使用phpstudy快速配置一个虚拟主机
说明:为了windows本地开发php方便,这里推荐使用PHP集成环境phpstudy. 目的:使用域名访问项目(tinywan.test) 1.官网:http://www.phpstudy.net ...
- Bitcoin Core钱包客户端的区块数据搬家指南
最近在饭团(微信中的一个服务号)里教一些朋友学习比特币和区块链技术,为了让大家深刻地理解去中心化网络和钱包等概念,我推荐大家一定要安装经典的Bitcoin Core钱包软件,有些朋友在安装的时候没有留 ...
- tomcat自动重新加载应用
前言 当应用配置文件发生变化时,无需重启tomcat,可以使tomcat重新加载应用. 场景 假设存在一个J2EE应用A,对应war文件名称为A.war,部署在tomcat的webapps目录下,即: ...
- ZooKeeper基础
======================================ZooKeeper 背景======================================ZooKeeper 是一 ...
- vue 获取时间戳对象转换为日期格式
//1. 简单页面展示用<template> <!-- time为时间戳 --> <div>{{time | formatDate}}</div> &l ...
- adb.exe已停止工作
提示adb.exe错误,我电脑上没有安装豌豆荚,也没运行其它应用,最后发现是360杀毒软件导致的,进程中关掉360Mobile即可.
- Hibernate主键生成策略及选择
1 .increment:适用于short,int,long作为主键,不是使用数据库自动增长机制 这是hibernate中提供的一种增长机制 在程序运行时,先进行查询:select max(id) f ...
- 五、文件IO——dup 函数
5.1 dup 函数---复制文件描述符 5.1.1 简单cat实现及输入输出重定向 io.c #include <sys/types.h> #include <sys/stat.h ...
- 练习:javascript弹出框及地址选择功能,可拖拽
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...