I have an integer data member called "students" in public part of my class and is used as an argument in the constructor. gradebook.h:
class gradebook
{
public:
int students = 10;
gradebook(string, int[]);
void SetCourseName(string _coursename);
...
private:
string coursename;
...
};
gradebook.cpp:
#include "gradebook.h"
gradebook::gradebook(string s1, int array[students])
{
SetCourseName(s1);
}
void gradebook::SetCourseName(string _coursename)
{
coursename = _coursename;
}
when I try to compile the code receive this error:
invalid use of non-static data member 'gradebook::students'
gradebook::gradebook(string s1, int array[students])
^
if I put 'static const' before 'int student = 10' the problem gets away.
why?
Aucun commentaire:
Enregistrer un commentaire