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. HDU 6374(拼三角形 **)

    题意是在给定的线段长中挑选出能拼成三角形的最长的三条边,输出三角形的周长.先对所有边排序,从大到小,满足两较短边之和大于第三边就输出,若从未输出过就输出 -1 #include <iostrea ...

  2. 015、调试Dockerfile(2019-01-04 周五)

    参考https://www.cnblogs.com/CloudMan6/p/6853329.html   Dockerfile构建镜像的过程   1.从base镜像运行一个容器 2.执行一条指令,对容 ...

  3. C# 使用 log4net 记录日志

    Ø  前言 在一般的开发应用中,都会涉及到日志记录,用于排查错误 或 记录程序运行时的日志信息.log4net 库是 Apache log4j 框架在 Microsoft .NET 平台的实现,是一个 ...

  4. interactivePopGestureRecognizer --- iOS侧滑的问题

    苹果一直都在人机交互中尽力做到极致,在iOS7中,新增加了一个小小的功能,也就是这个api:self.navigationController.interactivePopGestureRecogni ...

  5. Creating A Moddable Unity Game

    前言: 对游戏进行修改与拓展(MOD)是我一直以来感兴趣的东西,我的程序生涯,也是因为在初中接触到GBA口袋妖怪改版开始的,改过也研究过一些游戏的MOD实现方式,早就想在自己的游戏中实现“MOD系统” ...

  6. Rootkit介绍

    Rootkit 是一种特殊类型的 malware(恶意软件). Rootkit 之所以特殊是因为您不知道它们在做什么事情.Rootkit 基本上是无法检测到的,而且几乎不能删除它们. 虽然检测工具在不 ...

  7. jQuery.rotate.js笔记

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

  8. ASP.NET MVC - NPOI读取Excel

    引入: using System; using System.Data; using System.IO; using NPOI.SS.UserModel; using NPOI.XSSF.UserM ...

  9. Javascript - ExtJs - TreePanel组件

    TreePanel组件(Ext.tree.TreePanel)logogram:Ext.tree.Panel | xtype:treepanel 树与节点 树面板组件的根是源头,从根上拓展出其它的子节 ...

  10. 【转载】TensorFlow学习笔记:共享变量

    原文链接:http://jermmy.xyz/2017/08/25/2017-8-25-learn-tensorflow-shared-variables/ 本文是根据 TensorFlow 官方教程 ...