#include "stdafx.h"
#include
using namespace std;
class cat
{
public:
cat();
cat(cat*);
void setInfo(int age,int color,int weight);
void printInfo();
private:
int age;
int weight;
int color;
};
cat::cat()
{
}
cat::cat(cat* a_cat)
{
this->age = a_cat->age;
this->color = a_cat->color;
this->weight= a_cat->weight;
}
void cat::setInfo(int age,int color,int weight)
{
this->age = age;
this->color = color;
this->weight = weight;
}
void cat::printInfo()
{
cout<<"age is "<< age < <<"color is "< <<"weight is "<}
int _tmain(int argc, _TCHAR* argv[])
{
cat kitty;
kitty.setInfo(11,12,13);
cat lucy(&kitty);
lucy.printInfo();
return 0;
}
拷贝构造函数不是很难实现,先了解它的用法,然后再深入的思考它的意义。
运行结果如下:
age is 11
color is 12
weight is 13
请按任意键继续. . .
阅读(112) | 评论(0) | 转发(0) |