#include<iostream>
using namespace std;
int x; // global variable
void f() // function definition
{
static int y;
// int x;
extern int g();
class local // local class
{
int g() { return x; } // error, local variable x
// cannot be used by g
int h() { return y; } // valid,static variable y
int k() { return ::x; } // valid, global x
int l() { return g(); } // valid, extern function g
};
}
int main()
{
}
---------------------------------------------------------------------
Introduction To Local Class
A class can be declared inside a function or a block. In such cases, it is not visible from anywhere else, and instances thereof can only be created within the scope in which it is declared. This can be useful if you need to hide an ancillary object, which should not be accessible or used anywhere else: void f(const char *text)
No comments:
Post a Comment