以下是一段c++程序,不知道哪里有错啊?望各位高人指点一下!谢谢!

来源:百度知道 编辑:UC知道 时间:2024/05/22 00:22:30
#include<iostream.h>

class Cat {

private:
int itsAge;
static int HowMangCats;
public:
Cat(int age):itsAge(age) {HowMangCats++;}
~Cat() {HowMangCats--;}
int GetAge() {return itsAge;}
void SetAge(int age) {itsAge=age;}

static int Gethowmang() {return HowMangCats;
}
int Cat::HowMangCats=0;
void T();
int main()
{
const int Maxcats=3;
Cat *Cathouse[Maxcats];
int i;
for(i=0;i<Maxcats;i++)
{
Cathouse[i]=new Cat(i);
T();
}
for(i=0;i<Maxcats;i++)
{
delete Cathouse[i];
T();
}
return 0;
}

void T()
{
cout<<"there are "<<Cat::Gethowmang()<<"cats alive !"<<endl;
}

1>------ 已启动生成: 项目: Study, 配置: Debug Win32 ------
1>正在编译...
1>Study.cpp
1>e:\cpp集\study\study.cpp(31) : error C2086: “int Cat::HowMangCats”: 重定义
1> e:\cpp集\study\study.cpp(22) : 参见“Cat::HowMangCats”的声明
1>e:\cpp集\study\study.cpp(31) : error C2864: “Cat::HowMangCats”: 只有静态常量整型数据成员才可以在类中初始化
1>e:\cpp集\study\study.cpp(52) : error C2535: “void Cat::T(void)”: 已经定义或声明成员函数
1> e:\cpp集\study\study.cpp(32) : 参见“Cat::T”的声明
1>e:\cpp集\study\study.cpp(2211) : fatal error C1075: 与左侧的 大括号“{”(位于“e:\cpp集\study\study.cpp(18)”)匹配之前遇到文件结束
1>生成日志保存在“file://e:\Cpp集\Study\Debug\BuildLog.htm”
1>Study - 4 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

Cat类的定义少了一个结束的“};”

class Cat {

private:
int itsAge;
static int HowMangCats;
public:
Cat(int age