I have the following student class with two similar function- One is static and one is not.
class Student { public: Student(std::string name_ , int const id_); virtual ~Student(); void addGrade(int const grade2add);//grade above 100 void removeGrade (int const grade2remove); //update maxGrade void print(); //id, name, grades int getStudentMaxGrade(); static int getMaxGrade(); private: std::string name; //max 20 chars int const id; //5 digits, only digits std::vector<int> grades; float avg; static int maxGrade; static int freq_grades[100]; }; The static int maxGradeis initialize with 0.
I implement the function:
int Student::maxGrade = 0; int Student::getStudentMaxGrade() { return *max_element(grades.begin(), grades.end()); } I'm not sure how to implement the ststicstatic function. I tried:
int Student::getMaxGrade() { maxGrade= *max_element(grades.begin(), grades.end()); return maxGrade; } But it doesn't work (doesn't compile)