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的更多相关文章

  1. C++ Copy Elision

    故事得从 copy/move constructor 说起: The default constructor (12.1), copy constructor and copy assignment ...

  2. Copy Control settings

    Copy Control settings     Skip to end of metadata   Created by Rajesh Banka, last modified by Jyoti ...

  3. C++ std::deque

    std::deque template < class T, class Alloc = allocator > class deque; Double ended queue deque ...

  4. 词频统计_输入到文件_update

    /* 输入文件见337.in.txt 输出文件见338.out.txt */ #include <iostream> #include <cctype> #include &l ...

  5. algorithm之改变序列算法--待解决

    简述:改变序列算法,参见http://www.cplusplus.com/reference/algorithm/?kw=algorithm 待解决问题:iterator_traits.std::mo ...

  6. 《Effective Modern C++》翻译--简单介绍

    北京时间2016年1月9日10:31:06.正式開始翻译.水平有限,各位看官若有觉得不妥之处,请批评指正. 之前已经有人翻译了前几个条目,有些借鉴出处:http://www.cnblogs.com/m ...

  7. C++ Core Guidelines

    C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...

  8. 如果返回结构体类型变量(named return value optimisation,NRVO)

    貌似这是一个非常愚蠢的问题,因为对于具有良好素质的程序员而言,在C中函数返回类型为结构体类型是不是有点不合格,干嘛不用指针做传入传出呢? 测试环境:Linux IOS 3.2.0-45-generic ...

  9. <Effective C++>读书摘要--Templates and Generic Programming<一>

    1.The initial motivation for C++ templates was straightforward: to make it possible to create type-s ...

随机推荐

  1. openstack服务启动之nova-compute

    在openstack中,消息的传递一共有两种方式,分别是:服务之间的传递调用Restful api,服务中模块之间的传递使用消息队列.每一个模块在启动是都会启动消息队列,等待队列中的有消息到来.所以模 ...

  2. 前端面试题整理—ES6篇

    1.es5和es6的区别,说一下你所知道的es6 ECMAScript5,即ES5,是ECMAScript的第五次修订,于2009年完成标准化 ECMAScript6,即ES6,是ECMAScript ...

  3. impala系列: 时间函数

    --=======================时间函数--======================= --当前时间戳now()current_timestamp() --当前时间戳相对于 li ...

  4. 十种MYSQL显错注入原理讲解(三)

    这回间隔时间有点长了,年前年后忙的头晕眼花,外加大病.下面我继续讲解. 1.multipolygon() and multipolygon((select * from(select * from(s ...

  5. 2017CCPC秦皇岛 G题Numbers&&ZOJ3987【大数】

    题意: 给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n,并且要使得这m个数的或值最小. 思路: 从二进制的角度分析,如果这m个数中有一个数某一位为1,那么最后或起来这一位肯定是为1的, ...

  6. Git命令用于检查特定提交的差异

    假设你的提交日志如下(可以通过 git log 命名查看) commit 14af3315a2b1234daac74ece61ef913007043e06 Author: wuxianqiang &l ...

  7. scrapy模拟用户登录

    scrapy框架编写模拟用户登录的三种方式: 方式一:携带cookie登录,携带cookie一般请求的url为登录后的页面,获取cookie信息应在登录后的页面获取,cookie参数应转成字典形式 # ...

  8. jQuery.rotate.js笔记

    1. jQuery.rotate.js是什么 一个开源的兼容多浏览器的jQuery插件用来对元素进行任意角度的旋转动画. 这个库开发的目的是为了旋转img的,在3.x之后的版本可能支持其它元素,但旋转 ...

  9. window.name

    name 设置或返回存放窗口的名称的字符串.该名称是在 open()方法创建窗口时指定的或者使用一个<frame>标记的name属性指定的. 窗口的名称可用作一个<a>或者&l ...

  10. 【tmos】如何在Interceptor拦截器中注入其他数据

    光是这样是获取不到weixinConfig内容的 public class WebLoginInterceptor implements HandlerInterceptor { @Autowired ...