Explain what is nested class

Nested class:

A class defined within another class is a nested class.

Nested class' scope is within its enclosing class. Nested class name is not visible outside the enclosing class without qualifying it with enclosing class name. That is, enclosing_class_name::nested_class_name.

Example:

class Employee
{
public:
  class Data
  {

  public:
    int age;
    int unique_id;
    void display()
    { cout<<unique_id<< " " <<age; }

  };

  void printData( Data d)
  {
    d.unique_id=1;
    d.display();
  }
};

int  main()
{
  Employee jay;
  Employee::Data d;
  d.age=23;
  jay.printData(d);
}


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