Base Class Undefined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sir G
    New Member
    • Sep 2011
    • 7

    Base Class Undefined

    Hi all, I'm a novice C++ programmer (main language is java). I'm getting a C2504: base class undefined error, and have no idea why. Google told me this happens when the base class is indeed not defined before a class inheriting from the base class is defined, but this does not seem to be the problem here.

    Code:
    #ifndef GEOMETRY
    #define GEOMETRY
    
    #include "stdafx.h"
    #include "Intersectable.h"
    #include "HitRecord.h"
    #include "Ray.h"
    #include "BRDF.h"
    
    class Intersectable;
    class brdf;
    class HitRecord;
    
    class Geometry: public Intersectable {
    public:
    	virtual ~Geometry(){}
    	virtual bool intersect(const Ray &ray, HitRecord* record) = 0;
    
    	brdf *brdf;
    };
    
    #endif
    and Intersectable.h looks like:

    Code:
    #ifndef INTERSECTABLE
    #define INTERSECTABLE
    
    #include "stdafx.h"
    #include "Ray.h"
    #include "HitRecord.h"
    
    class HitRecord;
    class Ray;
    
    class Intersectable{
    public:
    	virtual ~Intersectable(){}
    	virtual bool intersect(const Ray &ray, HitRecord *record) = 0;
    };
    
    #endif
    other unrelated tips on the code style are welcome too :) I'm using visual studio 2010
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The error is not in the code you have posted.

    Double click on the error to see where the compiler got into trouble.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      There is nothing obvious wrong with the code posted (apart from the mildly questionable naming of a member variable with the type name at line 19) so I suspect it must be to do with code you have not posted.

      Also the exact error message(s) produced might help us diagnose the problem.

      Comment

      • Sir G
        New Member
        • Sep 2011
        • 7

        #4
        This is my console output;

        1>------ Build started: Project: RayTracer, Configuration: Debug Win32 ------
        1>Build started 17/07/2012 20:56:35.
        1>InitializeBui ldStatus:
        1> Touching "Debug\RayTrace r.unsuccessfulb uild".
        1>ClCompile:
        1> All outputs are up-to-date.
        1> OBJParser.cpp
        1>j:\raytracer\ raytracer\geome try.h(14): error C2504: 'Intersectable' : base class undefined
        1>j:\raytracer\ raytracer\objpa rser.cpp(14): warning C4244: 'argument' : conversion from 'obj::float_typ e' to 'float', possible loss of data
        1>j:\raytracer\ raytracer\objpa rser.cpp(14): warning C4244: 'argument' : conversion from 'obj::float_typ e' to 'float', possible loss of data
        1>j:\raytracer\ raytracer\objpa rser.cpp(14): warning C4244: 'argument' : conversion from 'obj::float_typ e' to 'float', possible loss of data
        1>
        1>Build FAILED.
        1>
        1>Time Elapsed 00:00:00.15
        ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

        So, the error is shown at line 14 of the first fragment of code.

        The code I have not posted is quite substantial...

        Comment

        • Sir G
          New Member
          • Sep 2011
          • 7

          #5
          Ok, so I removed a parser for .obj-files from my solution, and that fixed the problem. This is odd, since these are quite unrelated pieces of code.

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Probably becuase you removed the file that had the problem.

            Look in OBJParser.cpp. That was the file being compiled. The error was line 14 of geometry.h.

            Maybe you could post the first part of the file. Like to be sure you included intersectable.h .


            Projects build by compiling each .cpp file separately. Each file must compile based on its own code. What you do in other.cpp files is irrelevant.

            Comment

            Working...