Thread: problems with including headers

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    630

    problems with including headers

    Hello..

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

    Code:
    //header 1
    #include "header2.h"
    class headerone {
    public:
    	headertwo *sth;
    };
    
    //header 2
    #include "header1.h"
    class headertwo {
    public:
    	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
    Location
    Tehran
    Posts
    1,246
    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
    Location
    The edge of the known universe
    Posts
    39,661
    You need include guards
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    Like
    #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
    Posts
    7,366
    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