Thread: Classes and Structs

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    34

    Classes and Structs

    Hi
    Could someone show me an example of how to use a struct in a base class and then access the struct from a child class? Thanks for any help!

    Code:
    class cBase_Class
    {
       protected:
                 //members
       public:
            
                struct MyStruct
                  {
                       char name[20];
                       int age;
                  };
     };
             
    class cChild : public cBase_Class
         //how do I access the struct in the base class?
    };

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    same way you would as if you had declared it in the derived class. With public inheritance all public members of the base class are also public members of the derived class.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structs or classes?
    By legit in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2009, 10:16 AM
  2. classes, structs and unions
    By Luciferek in forum C++ Programming
    Replies: 24
    Last Post: 08-09-2008, 10:26 AM
  3. Why use Classes instead of Structs?
    By yaya in forum C++ Programming
    Replies: 12
    Last Post: 03-16-2008, 12:39 AM
  4. Are structs and classes the same thing?
    By dwks in forum C++ Programming
    Replies: 6
    Last Post: 11-25-2005, 03:21 PM
  5. Classes or Structs faster for Lists
    By White Rider in forum C++ Programming
    Replies: 24
    Last Post: 04-05-2002, 03:57 PM