有关类的定义函数
这是我老师写的一个程序的类的部分,我想问下:
int GetScore1(){return nScore1;}
int GetScore2(){return nScore2;}
int GetScore3(){return nScore3;}
这些为什么定义函数后有个{},里面有返回函数,这个老师上课没提到,而且我们平时写程序的时候就直接是
int Getscore1(),就完了,后面没有return那些了
class Student {private: //私有成员变量定义 string strName; //定义字符串,用于存放学生的姓名 unsigned long nIndex; //学生的索引值 int nScore1; int nScore2; int nScore3; //学生的成绩 public: //公有成员函数定义 Student(string _name="somebody",unsigned long _index=2008010001, int _score1=100,int _score2=100,int _score3=100): strName(_name),nIndex(_index),nScore1(_score1),nScore2(_score2),nScore3(_score3){ } string GetName() { return strName; } unsigned long GetIndex() { return nIndex; } int GetScore1() { return nScore1; } int GetScore2() { return nScore2; } int GetScore3() { return nScore3; }};int Getscore1() // 程序声明!int GetScore1() { return nScore1; } // 程序定义!返回值为 int 的一定要返回一个整数! 有些编译器可以帮你做了!所以不写也不会出错!但是其他不敢保证!
[解决办法]
看基础吧···
把你的教材多看几遍···
估计楼上讲的你都听不懂···