Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Nested class definitions (http://www.velocityreviews.com/forums/t291158-nested-class-definitions.html)

Tony Johansson 05-18-2005 11:22 PM

Nested class definitions
 
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();
};
};




Victor Bazarov 05-19-2005 02:27 AM

Re: Nested class definitions
 
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




All times are GMT. The time now is 02:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.