刚开始学习c++, 例子里某个函数方法求助
刚开始学习c++, 例子里某个函数方法求助:GetAge()方法不返回初始化的值。代码运行没有错误!!!
#include <iostream>
class NiaoRen{
public:
int GetAge();
void SetAge(int age);
void Meow();
private:
int itsAge;
};
//GetAge, public accessor function
//return value of itsAge member
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;
JiangBo.SetAge(30);
JiangBo.Meow();
std::cout << "Jiang Bo is a Niao Ren who is:";
std::cout << " years old.\n";
JiangBo.Meow();
system("pause");
}