Thread: Problem with #include dependencies

  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,708
    You are going to have to merge the two files...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  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, 10: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, 04: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, 01:21 PM