Thread: Class scope variables

  1. #1
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87

    Class scope variables

    Can anyone tell me what the advantage of declaring a class as follows is?
    Code:
    class CQueue
    {
    // Class scope variables
    struct Node { Item item; struct Node *next;};
    
    private:
    ...
    public:
    ...
    };
    What is the benefit of declaring the struct for the queue outside of the scope modifier tags? Woudln't declaring it as public be exactly the same?
    Visual C++ .net
    Windows XP profesional

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Woudln't declaring it as public be exactly the same?

    No, the default access for a class is private. So, the struct in your code is a "nested" struct within your class that has private access--so nothing outside the class can create a Node. Since a struct has a default access of public, the members inside the struct are public, and therefore they can be freely accessed by member functions of the enclosing class.
    Last edited by 7stud; 08-23-2003 at 01:57 AM.

  3. #3
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87
    Cheers.
    Visual C++ .net
    Windows XP profesional

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Cleaning variables for a CGI app (as a derived class?)
    By drrngrvy in forum C++ Programming
    Replies: 1
    Last Post: 02-01-2006, 12:34 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Class Constructor variables
    By neandrake in forum C++ Programming
    Replies: 2
    Last Post: 03-17-2005, 02:19 PM