Results 1 to 5 of 5

Thread: What is Nested Class in C++?

  1. #1
    Join Date
    Dec 2010
    Posts
    14

    What is Nested Class in C++?

    Hello friends, I am a student from I.t field where in I am learning programming language. Currently, I am studying C++ programming language where in I am having a problem in Nested Class. I am not able to understand this term. I wanted to know what this term is actually. I get confused when I try to study. So, please make me understand this term. If anyone having any knowledge regarding this topic then please let me know as soon as possible.

  2. #2
    Join Date
    Apr 2009
    Posts
    569

    Re: What is Nested Class in C++?

    When a class is defined within another class, it is known as nested class. By defining one class within another the scope of the inner class is restricted to outer class. The term nested class is restricted to its surrounding class. Except that you use the term like object, references, explicit pointers, names, declarations in a nested class can only use noticeable constructs, which includes static members, and enumerators from the encircling class and global variables.

  3. #3
    Join Date
    May 2009
    Posts
    529

    Re: What is Nested Class in C++?

    Code:
    	For example
    #include<iostream.h>
    class person
    {
       char name[20];
             class date
                   {
                    int dd,mm,yy;
                      public:
                             void get_date()
                              {
                                  cout<<”enter date(dd\mm\yy)”;
                                   cin>>dd>>mm>>yy;
                                 }
                               void display
                                {
                              cout<<dd<<mm<<yy;
                                 }birth_date;
                         }
             Public:
        void get_data()
             {
                cout<<”enter name of person”;
                 cin>>name;
                 cout<<”enter birth date”;
                  cin>>birth_date.get_date();
              }
         void show()
           {
                cout<<”name”<<name;
                cout<<”birth date “<<birth_date.display();
            }
    }
    main()
    {
    Person p;
    p.get_data();
    p.show();
    }

  4. #4
    Join Date
    Apr 2009
    Posts
    488

    Re: What is Nested Class in C++?

    Well, you must know that member functions of a nested class pursues standard access regulations and which have no particular access privileges to members of their enclosing classes. I think that this is something which you won’t be finding in any other class. One more important thing to note is that member functions of the enclosing class have no individual access to members of a nested class.

  5. #5
    Join Date
    May 2009
    Posts
    511

    Re: What is Nested Class in C++?

    Code:
     class X {
    private:
      class Y { };
      Y *c;
    
      class Z : private Y {
      private:
          Y b;
    //      X::Y b2;
          Z *a;
    //      X::z *a2;
        };
    };
    In the above example you will find that the nested class X::Z is been inherited from X::Y which is shown in the above program. Now, here you can notice that the compiler permits declarations X::Y y2 and X::Z *x2 because both X::Y and X::Z are private. I think that this example might have cleared all your doubts in Nested class in C++.

Similar Threads

  1. How to run Nested Vms
    By Vitel in forum Operating Systems
    Replies: 8
    Last Post: 15-09-2011, 11:54 AM
  2. CPP : nested class in a templated class
    By Gavyn in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 04:34 PM
  3. Problem of nested query
    By MAGAR in forum Software Development
    Replies: 4
    Last Post: 09-12-2009, 09:55 PM
  4. What does nested loops means?
    By Zhankana_n in forum Software Development
    Replies: 5
    Last Post: 27-11-2009, 11:18 AM
  5. Nested DataTable for GridView
    By Renderman21 in forum Software Development
    Replies: 3
    Last Post: 08-05-2009, 02:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,637,461.63493 seconds with 17 queries