Chinaunix首页 | 论坛 | 博客
  • 博客访问: 16189
  • 博文数量: 14
  • 博客积分: 245
  • 博客等级: 二等列兵
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-28 13:45
文章分类

全部博文(14)

文章存档

2013年(9)

2012年(5)

我的朋友

分类: C/C++

2012-12-31 15:41:18

#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) |
给主人留下些什么吧!~~