Explain what is local class

Local class in C++ :
A class defined inside a function is a local class.

Example:
void printData()
{
  static int count=0;
  count++;

 class Data
 {
   public:
   int age;
   int unique_id;
   void display()
    { cout<< count << " " << unique_id << " " <<age; }
    
 };
 Data jay;
 jay.age=25;
 jay.unique_id=1;
 jay.display();
}

int  main()
{
  printData();
}


Scope of local class is within the enclosing function where it is defined.

It has same access permission to the identifier outside the enclosing function as the enclosing function.
The enclosing function does not have special access to members of the local class. Also all the member function's definition needs to be defined within class definition.

A local class cannot have static data members.
0 Response on this
click to Post
Login to comment.
Why create separate log in id? Log in with your
log in with your google account to post comment
Leave your comment:
*
*
Post