header files,sub classes

This is a discussion on header files,sub classes within the C++ Programming forums, part of the General Programming Boards category; When writing inheritance in c++.Do i need to include the header files of all my sub classes into the base ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,506
    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)
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



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, 10: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, 01:10 PM
  5. Classes and header files
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-23-2002, 11:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21