标签:
// 复制构造函数.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