Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is Nested Class in C++?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 02-01-2011
Member
 
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.

Reply With Quote
  #2  
Old 02-01-2011
Member
 
Join Date: Apr 2009
Posts: 567
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.
Reply With Quote
  #3  
Old 02-01-2011
Member
 
Join Date: May 2009
Posts: 525
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();
}
Reply With Quote
  #4  
Old 02-01-2011
Member
 
Join Date: Apr 2009
Posts: 484
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.
Reply With Quote
  #5  
Old 02-01-2011
Member
 
Join Date: May 2009
Posts: 503
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++.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is Nested Class in C++?"
Thread Thread Starter Forum Replies Last Post
How to run Nested Vms Vitel Operating Systems 8 15-09-2011 11:54 AM
CPP : nested class in a templated class Gavyn Software Development 5 12-02-2010 04:34 PM
Problem of nested query MAGAR Software Development 4 09-12-2009 09:55 PM
What does nested loops means? Zhankana_n Software Development 5 27-11-2009 11:18 AM
Nested DataTable for GridView Renderman21 Software Development 3 08-05-2009 02:08 PM


All times are GMT +5.5. The time now is 01:01 PM.