码迷,mamicode.com
首页 > 其他好文 > 详细

剑指offer 复制构造函数

时间:2016-12-13 23:19:15      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:函数   blog   pre   include   int   bsp   stream   space   print   

复制构造函数:

 A(const A &other){value=other.value;} 也就是传值参数改为常量引用。

#include<iostream>
using namespace std;
class A
{
    private:
        int value;
    public:
        A(int n){value=n;}
        A(const A &other){value=other.value;}
        void print(){
            cout<<value<<endl;
        }
};
int main()
{
    A a=10;
    A b=a;
    b.print();
    return 0;
}

 

剑指offer 复制构造函数

标签:函数   blog   pre   include   int   bsp   stream   space   print   

原文地址:http://www.cnblogs.com/wft1990/p/6172197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!