473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Base Class Undefined

7
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.

Expand|Select|Wrap|Line Numbers
  1. #ifndef GEOMETRY
  2. #define GEOMETRY
  3.  
  4. #include "stdafx.h"
  5. #include "Intersectable.h"
  6. #include "HitRecord.h"
  7. #include "Ray.h"
  8. #include "BRDF.h"
  9.  
  10. class Intersectable;
  11. class brdf;
  12. class HitRecord;
  13.  
  14. class Geometry: public Intersectable {
  15. public:
  16.     virtual ~Geometry(){}
  17.     virtual bool intersect(const Ray &ray, HitRecord* record) = 0;
  18.  
  19.     brdf *brdf;
  20. };
  21.  
  22. #endif
and Intersectable.h looks like:

Expand|Select|Wrap|Line Numbers
  1. #ifndef INTERSECTABLE
  2. #define INTERSECTABLE
  3.  
  4. #include "stdafx.h"
  5. #include "Ray.h"
  6. #include "HitRecord.h"
  7.  
  8. class HitRecord;
  9. class Ray;
  10.  
  11. class Intersectable{
  12. public:
  13.     virtual ~Intersectable(){}
  14.     virtual bool intersect(const Ray &ray, HitRecord *record) = 0;
  15. };
  16.  
  17. #endif
other unrelated tips on the code style are welcome too :) I'm using visual studio 2010
Jul 17 '12 #1

✓ answered by Sir G

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.

5 6793
weaknessforcats
9,208 Expert Mod 8TB
The error is not in the code you have posted.

Double click on the error to see where the compiler got into trouble.
Jul 17 '12 #2
Banfa
9,065 Expert Mod 8TB
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.
Jul 17 '12 #3
Sir G
7
This is my console output;

1>------ Build started: Project: RayTracer, Configuration: Debug Win32 ------
1>Build started 17/07/2012 20:56:35.
1>InitializeBuildStatus:
1> Touching "Debug\RayTracer.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> OBJParser.cpp
1>j:\raytracer\raytracer\geometry.h(14): error C2504: 'Intersectable' : base class undefined
1>j:\raytracer\raytracer\objparser.cpp(14): warning C4244: 'argument' : conversion from 'obj::float_type' to 'float', possible loss of data
1>j:\raytracer\raytracer\objparser.cpp(14): warning C4244: 'argument' : conversion from 'obj::float_type' to 'float', possible loss of data
1>j:\raytracer\raytracer\objparser.cpp(14): warning C4244: 'argument' : conversion from 'obj::float_type' 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...
Jul 17 '12 #4
Sir G
7
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.
Jul 17 '12 #5
weaknessforcats
9,208 Expert Mod 8TB
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.
Jul 18 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: John Harrison | last post by:
This code fails to compile on Comeau C++ and VC++ 7.1 (with language extensions disabled) template <class T> struct B { T b; }; template <class T>
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
4
by: Alfonso Morra | last post by:
Hi, I have a variable that stores a pointer to a base class. I am using this variable to store pointers to objects of the base class, as well as pointers to other derived classes. However,...
8
by: LAvoisieR | last post by:
Following test code behaviour suprised me and I dont know what's wrong with this. I have two overloaded constructors within base class and virtual destructor implemented. Derived class uses...
3
by: hurcan solter | last post by:
Consider the code fragment; class A { public: A(){} A(int prm):mprm(prm){} int mprm; }; class B:public A {
4
by: OiNutter | last post by:
Hi I have a web service with a reference to a class library with 2 classes; User: The base class Client: Inherits from User There are also some functions which return an object of type...
13
by: Rahul | last post by:
Hi Everyone, I was just playing around virtual functions and landed up with the following, class Base1 { public: virtual void sample() { printf("base::sample\n");
6
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a...
8
MrPickle
by: MrPickle | last post by:
I wasn't sure what to call them so I'll just call them child classes. I have a child class: class Label : public Window, but I need to use a Label in Window, is this possible? If so how? I...
19
by: Juha Nieminen | last post by:
Assume I have a class Base, and then this: struct Derived: public Base { AnotherClass member; }; Also assume that I'm allocating an object of type 'Derived' with a custom allocator and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.