Thread: problems with including headers

  1. #1
    Registered User
    Join Date
    May 2006

    problems with including headers


    I have 2 headers in my program that have classes like:

    //header 1
    #include "header2.h"
    class headerone {
    	headertwo *sth;
    //header 2
    #include "header1.h"
    class headertwo {
    	headerone *sth;
    I get compiling problems. I would put them together, but I want to keep familiar stuff together. What would be the best way to solve the problems?

    Thanks a lot

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Write the class in header file and include it in your cpp file.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You need include guards

    #ifndef DATA_H
    #define DATA_H
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jan 2005
    You also need to use a forward declaration. Since you are using only a pointer to the other class, just forward declare it instead of including the other header.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. including headers and forward declaration
    By l2u in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2007, 02:47 PM
  3. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  4. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  5. Common Problems
    By WolfPack in forum C Programming
    Replies: 4
    Last Post: 01-28-2003, 06:38 PM