Problem with #include dependencies

This is a discussion on Problem with #include dependencies within the C Programming forums, part of the General Programming Boards category; I'm having a problem with the order of my header files... Code: #ifndef Sphere_H #define Sphere_H #include "DoubleVector.h" #include "Object.h" ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    752

    Problem with #include dependencies

    I'm having a problem with the order of my header files...
    Code:
    #ifndef Sphere_H
    #define Sphere_H
    
    #include "DoubleVector.h"
    #include "Object.h"
    
    typedef struct {
      DoubleVector center;
      double radius;
    } SphereData;
    
    void makeSphere (double centerX, double centerY, double centerZ, double radius, 
    Object * result);
    
    #endif // Sphere_H
    Code:
    #ifndef Object_H
    #define Object_H
    
    #include "Ray.h"
    #include "Sphere.h"
    
    typedef union {
      SphereData sphereType;
    } ObjectData;
    
    typedef struct {
      // Shoot fires a ray at the object and stores the t-value in t.  Returns 1 on 
    success
      int (*shoot) (ObjectData const *, Ray const *, double * t);
      int (*hit) (ObjectData const *, Ray const *, double t);
    } ObjectFunctions;
    
    typedef struct {
      ObjectData objData;
      ObjectFunctions * objFunctions;
    } Object;
    
    #endif // Object_H
    Notice how Object.h and Sphere.h depend on each other. This is creating a pretty irritating problem if I try to include either file. What I need is some kind of way to prototype my typedefs, but I don't know how to do this, any help
    Callou collei we'll code the way
    Of prime numbers and pings!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,639
    You are going to have to merge the two files...
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    I believe if you add "extern struct Object;" to the top of sphere.h will allow you to avoid merging the 2 files.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 09:08 PM
  2. Problem with multiple pipes...
    By LightsOut06 in forum C++ Programming
    Replies: 0
    Last Post: 10-28-2005, 10:15 AM
  3. include problem
    By Strait in forum C++ Programming
    Replies: 4
    Last Post: 01-31-2005, 03:01 PM
  4. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM
  5. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 12:21 PM

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