using namespace std;
class test{
private:
int a,b;
public:
static int count=0;
test(int a=10,int b=10){
count++;
}
};
int main(){
test t;
cout<<t.count<<endl;
test t1;
cout<<t1.count<<endl;
}
I have used static member which is initialized inside the class, I have tried outside the class it works fine, but I don't get how is that a error in first place which is initializing the member inside class.
When I run the above code it gives me the following error: ISO C++ forbids in-class initialization of non-const static member 'test::count'.
Why I cant initialize a static member inside class?