Thread: header files,sub classes

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    118

    header files,sub classes

    When writing inheritance in c++.Do i need to include the header files of all my sub classes into the base class.The reason i am asking is i have a base class a which has sub classes b,c,d, and e.I want to use sub classes b,c,d, and e as member variables in a separate class f and i included the header file for base class a in f but it doesn't work.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by sigur47 View Post
    When writing inheritance in c++.Do i need to include the header files of all my sub classes into the base class.The reason i am asking is i have a base class a which has sub classes b,c,d, and e.I want to use sub classes b,c,d, and e as member variables in a separate class f and i included the header file for base class a in f but it doesn't work.
    Include the headers for b,c,d and e into the declaration file of f. (Don't forget preprocessor guards so something is not included more than once.)
    Typically, a base class should not know about its children.(Which would potentially bring a lot a circular dependency problems)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes and header files
    By sigur47 in forum C++ Programming
    Replies: 2
    Last Post: 01-21-2012, 05:56 PM
  2. Header files and classes
    By disruptivetech in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2008, 09:02 AM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Header Files and Classes.
    By Lithorien in forum C++ Programming
    Replies: 10
    Last Post: 08-13-2004, 12:10 PM
  5. Classes and header files
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-23-2002, 10:42 AM