Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Nested class definitions

Reply
Thread Tools

Nested class definitions

 
 
Tony Johansson
Guest
Posts: n/a
 
      05-18-2005
Hello!

What is the difference if we have the whole class Item defined within class
List see NOTE_1 below compare to
having class Item defined stand-alone and only have an instance of class
Item in the private section like NOTE_2.
Is it any advantage to nest a class definition within another class
definition such as this List class below.

Many thanks!

//Tony

NOTE_2
********
class List
{
public
....
private:
Item obj;
};

Assume we have this nested class definition

NOTE_1
*******
class List
{
public
....
private:
class Item
{
public:
item();
};
};



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      05-19-2005
Tony Johansson wrote:
> What is the difference if we have the whole class Item defined within
> class List see NOTE_1 below compare to
> having class Item defined stand-alone and only have an instance of
> class Item in the private section like NOTE_2.


The former case (NOTE_1) does not have an _instance_ of 'item' in
a 'List' object.

> Is it any advantage to nest a class definition within another class
> definition such as this List class below.


It only limits the scope of the nested class.

Unlike Java, C++ does not automatically create an instance of the
nested class in the outer class.

> Many thanks!
>
> //Tony
>
> NOTE_2
> ********
> class List
> {
> public
> ...
> private:
> Item obj;
> };
>
> Assume we have this nested class definition
>
> NOTE_1
> *******
> class List
> {
> public
> ...
> private:
> class Item
> {
> public:
> item();
> };
> };


V


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
moving class indepdent methods out of class definitions Rainer Weikusat Perl Misc 1 03-08-2013 06:41 PM
Nested Arrays in Method Definitions--a puzzle Jonah Bloch-Johnson Ruby 3 08-20-2008 02:38 AM
Nested Parameter Definitions Paddy Python 10 02-26-2007 08:20 AM
Is nested class automatically friend of class that it is nested in? request@no_spam.com C++ 5 09-25-2006 08:31 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM



Advertisments