I know we cannot declare a static member variable inside a local class... but the reason for it is not clear.
So please can anybody explain it?
Also, why can't we access a non-static variable define inside the function, within which the local class has been defined,directly in the local class member functions?
In the code given below:
int main(int argc, char *argv[])
{
static size_t staticValue = 0;
class Local
{
int d_argc; // non-static data members OK
public:
enum // enums OK
{
value = 5
};
Local(int argc) // constructors and member functions OK
: // in-class implementation required
d_argc(argc)
{
// global data: accessible
cout << "Local constructor\n";
// static function variables: accessible
staticValue += 5;
}
static void hello() // static member functions: OK
{
cout << "hello world\n";
}
};
Local::hello(); // call Local static member
Local loc(argc); // define object of a local class.
return 0;
}
Static variable staticValue is directly accessible while on the other hand argc argument from main is not....