What design problem does the following program have?

来源:百度知道 编辑:UC知道 时间:2024/06/19 04:43:18
What design problem does the following program have?
#include <iostream>
using namespace std;

class Critter
{
public:
int GetHunger() const {return m_Hunger;}
private:
int m_Hunger;
};

int main()
{
Critter crit;
cout<< ctri.GetHunger()<<endl;
return 0;
}

Thanks!!
手误:

cout<< crit.GetHunger()<<endl;

m_Hunger变量你还没初始化,同时Class Critter中你应该提供对他初始化的方法。

1.Missing ';' behind 'int GetHunger() const {return m_Hunger;} '
2.You should initialize member variable first before using it.

initialize m_Hunger