![]() |
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(); }; }; |
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 03:51 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.