I want to know if a protected static member can be initialized from a subclass.
For instance,
class Test
{
protected:
static int i;
};
class Test2 : public Test{};
#include "headfile.h"
int Test2::i = 1;
As you can see, when I initialize this static member (i), I use the name of the subclass (Test2).
To my surprise, I tested this code with visual studio 2013 and it worked without errors. But if I tried this with Netbeans (gcc11) under Linux, and I got a hint error:
unable to resolve the identifier i
Then I compiled it, error message:
error: ISO C++ does not permit ‘Test::i’ to be defined as ‘Test2::i’ [-fpermissive]
Now, if I change the protected publication for static int iin the class test, the error will disappear.
I got confused ... This is my first time I found two different results with gcc and vs.