Thread: What is the need of nested Class?

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    New York
    Posts
    24

    What is the need of nested Class?

    Hi All,

    We can not access the data member of a class nested with in another class.It does not get instantiated also.So what are the use of having a class nested with in another class?

    Thanks and Regards,
    A

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    You can access the data, depending on whether it is visible from whatever scope you're in. I'm not sure what you mean by "it does not get instantiated".

    If I'm understanding you, you mean something like std::list<T>::iterator ? Post some code, and we can hammer out any errors or troubles you might be having.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The only change of a nested class is that it will be located inside the first class.
    class A { class B {}; };
    To create class B, you will need to do A::B someth;
    What's the use? Consider if the class is only supposed to be use by the class it resides in, or if it makes sense to access it via A::B.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    For example, in a linked list container, it makes sense to make the list node an inner class, because no one else has any business accessing that class.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Nesting classes and structs within classes normally shows ownership. I don't do it very often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can Nested class access parent class's private member?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 08:42 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. nested class as friend
    By c++isugly in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2002, 05:36 PM