problems with including headers

This is a discussion on problems with including headers within the C++ Programming forums, part of the General Programming Boards category; Hello.. I have 2 headers in my program that have classes like: Code: //header 1 #include "header2.h" class headerone { ...

  1. #1
    l2u
    l2u is offline
    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,231
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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, 05:35 AM
  4. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  5. Common Problems
    By WolfPack in forum C Programming
    Replies: 4
    Last Post: 01-28-2003, 05:38 PM

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