#include <iostream>
#include <string>
class Base
{
static std::string s;
};
template<typename T>
class Derived
: Base
{
public:
Derived()
{
std::cout << s << std::endl;
}
};
std::string Base::s = "some_text";
int main()
{
Derived<int> obj;
}
This programs compiles and runs normally. static variable s
is private in base class that is inherited privately. How is Derived class accessing it?
If Derived class is not template, compiler complains about accessing private variable.
[aminasya@amy-aminasya-lnx c++]$ g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.