初学C++求助
出错的语句在程序里做了注释: 谢谢//demontrates of constructor and destructor
#include <iostream>
class NiaoRen{
public:
NiaoRen(int initialAge);
~NiaoRen();
int GetAge();
void SetAge(int age);
void Meow();
void Profession();
//bool Accessment();
private:
int itsAge;
};
//GetAge, public accessor function
//return value of itsAge member
/*bool NiaoRen::Accessment()
{
std::cout <<"Good=1 or bad=0 guy\n" ;
}*/
NiaoRen::NiaoRen(int initialAge)
{
itsAge=initialAge;
}
NiaoRen::~NiaoRen()
{
}
void NiaoRen::Profession()
{
std::cout << "Programmer\n";
}
int NiaoRen::GetAge()
{
return itsAge;
}
//definition of SetAge, public
//sets itsAge memeber
void NiaoRen::SetAge(int age)
{
itsAge = age;
//age=30;
}
//meow method, returns void parameters:none action.prints meow on screen
void NiaoRen::Meow()
{
std::cout << "Meow\n";
}
int main()
{
NiaoRen JiangBo(28);//default constructor
//JiangBo.SetAge(30);
//JiangBo.Meow();
std::cout << "NiaoRen was:\n";
// std::cout << JiangBo GetAge() << " years old.\n\007";//这里出错
// << " years old.\n";
JiangBo.Meow();
JiangBo.SetAge(30);
std::cout << "Jiang Bo is a Niao Ren who is ";
std::cout << JiangBo.GetAge() << " years old.\n\007";
JiangBo.Meow();
JiangBo.Profession();
system("pause");
}