首页 > 其他 > 详细

复制构造函数

时间:2016-05-25 23:50:02      阅读:291      评论:0      收藏:0      [点我收藏+]

// 复制构造函数.cpp : 定义控制台应用程序的入口点。
//复制构造函数:类(const 类&对象(随便起))
/*
Box(const Box&box)
{
length = box.length;
width = box.width;
height = box.height;
}
*/

#include "stdafx.h"
#include<iostream>
using namespace std;
class Box
{
private:
    int length;
    int width;
    int height;
public:
    Box(int a, int b, int c);
    Box(const Box&box)
    {
        length = box.length;
        width = box.width;
        height = box.height;
    }
    void display()
    {
        cout << length*width*height << endl;
    }
   
};


Box::Box(int a, int b, int c)
{
    length = a;
    width = b;
    height = c;
    display();
}
int main()
{
    Box box1(1, 2, 3);
    Box box2 = box1;
     box2.display();
    system("pause");
    return 0;
}

技术分享

复制构造函数

原文:http://www.cnblogs.com/summercloud/p/5529001.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!