Local Class In C++
A class declared inside a function is known as a
local class in C++ as it is local to that function.
A local class name can only be used in its
function and not outside it. Also, the methods of a local class must be defined
inside it only. A local class cannot have static data members but it can have
static functions.
Program:
#include<iostream.h>
#include<conio.h>
class emp;
void func()
{
class localclass
{
private:
int
num;
public:
void
get(int n)
{
num=n;
}
void
put()
{
cout<<”the
number is “<<endl;
}
};
localclass
obj;
obj.get(9);
obj.put();
}
void
main()
{
cout<<”demonstration
of local class in c++”<<endl;
func();
getch();
}
Output:
Demonstration
of local class in c++
The
number is 9
No comments:
Post a Comment