The following code is throwing an error message and I can't figure out what the issue is - is it the word static
, or const
? What am I doing wrong?
#include <iostream>
using namespace std;
class SampleClass
{
private:
int value;
static int counter;
public:
SampleClass(int i)
{
value = i;
counter++;
}
static int countSomeClass() const
{
return counter;
}
void showValue()
{
cout << value << endl;
}
};
int main()
{
SampleClass test(50);
test.showValue();
test.countSomeClass();
return 0;
}
Error message:
main.cpp:16:35: error: static member function static int SampleClass::countSomeClass() cannot have cv-qualifier
static int countSomeClass() const
static
function cannot beconst
. It is the combination that is the problem.