...which I cannot seem to figure out, for whatever reason. I've tried cleaning my build files in Qt as well, and that hasn't seemed to work either.
First off, let me state that I'm well aware that this error typically crops up when a C++ class inherits an abstract class with pure virtual functions, and the inheriting class (for whatever reason) hasn't defined them yet.
The issue is that there are NO pure virtual functions which exist in relation to the error specified.
I have a base class known as CoordinateObject
, with an abstract class, Shape
, which inherits from that base class, along with a FirstPersonCamera
class which also inherits from CoordinateObject
. Now, my Cubef
class inherits from Shape
, and when I try to compile the code, I get the following errors:
./debug\Camera.o:Camera.cpp:(.rdata$_ZTVN6Engine17FirstPersonCameraE[vtable for Engine::FirstPersonCamera]+0x10): undefined reference to `Engine::FirstPersonCamera::InitCoordinates()'
./debug\Cubef.o:Cubef.cpp:(.rdata$_ZTVN6Engine5CubefE[vtable for Engine::Cubef]+0x1c): undefined reference to `Engine::Cubef::InitCoordinates()'
Originally this cropped up when CoordinateObject
did have a pure virtual function InitCoordinates
, however, after trying to implement that properly within every class which chose to inherit from it, it still didn't work. Thus, I removed it (along with every class implementation and declaration except for the base class itself).
So, I need to know exactly what I'm doing wrong here. I'll post code as follows:
Code
CoordinateObject.h
class CoordinateObject
{
public:
CoordinateObject( void );
virtual ~CoordinateObject( void )
{
delete mWorld;
delete mObject;
delete mInertial;
}
Matrix3fv GetInertialSpace( void );
Matrix3fv GetObjectSpace( void );
Matrix3fv GetWorldSpace( void );
void SetInertialSpace( Matrix3fv* space );
void SetInertialSpace( Matrix3fv& space );
void SetObjectSpace( Matrix3fv* space );
void SetObjectSpace( Matrix3fv& space );
void SetWorldSpace( Matrix3fv* space );
void SetWorldSpace( Matrix3fv& space );
protected:
Matrix3fv* mWorld;
Matrix3fv* mObject;
Matrix3fv* mInertial;
private:
void InitCoordinates( void );
};
Shape.h
#pragma once
#include "stdafx.h"
namespace Engine
{
class Circlef;
class Shape
: public CoordinateObject
{
public:
Shape( Vector3f& center, float radius );
virtual ~Shape( void )
{
delete mCenter;
}
virtual void Collide( Shape& s ) = 0;
virtual void Collide( const Circlef& s ) = 0;
Vector3f* Center( void );
virtual void Draw( void ) = 0;
void SetCenter( Vector3f newCenter );
void SetCenter( Vector3f* newCenter );
float mRadius;
protected:
Vector3f* mCenter;
private:
void InitShape( Vector3f& center );
};
}
Cubef.h
#pragma once
#include "stdafx.h"
namespace Engine
{
class Cubef
: public Shape
{
public:
Cubef( Vector3f center, float radius );
virtual ~Cubef( void )
{
delete mCenter;
}
virtual void Collide( Shape& s );
virtual void Collide( const Circlef& s );
virtual void Draw( void );
void Draw( const Vector3f& camPosition );
void Draw( const Vector3f& newCenter, float radius, const Vector3f& camPosition );
void DrawFront( void );
void DrawBack( void );
void DrawLeft( void );
void DrawRight( void );
void DrawTop( void );
void DrawBottom( void );
inline double GetEdgeLength( void ) const
{
return mEdgeLength;
}
inline int GetCubeId( void ) const
{
return mCubeId;
}
inline double GetSurfaceArea( void ) const
{
return mSurfaceArea;
}
void Rotatef( float angle, AngleOfRotation aor );
void Rotatef( float angle, Vector3f* toRotate, AngleOfRotation aor );
protected:
static int CubeCount;
const int mCubeId;
float mSurfaceArea;
float mEdgeLength;
private:
};
}
And finally, Camera.h
namespace Engine
{
extern const float PI;
extern const double MOUSE_Y_SENSITIVITY;
extern const double MOUSE_X_SENSITIVITY;
extern const int FP_CAM_QUAT_ARR_LEN;
class FirstPersonCamera
: public CoordinateObject
{
public:
FirstPersonCamera( void );
~FirstPersonCamera( void );
void Rotate( SDL_Event*& event );
inline Vector3f GetPosition( void ) const
{
return *mPosition;
}
inline Matrix3fv GetRotation( void ) const
{
return *mRotation;
}
void MoveCamera( const SDL_KeyboardEvent& event );
void UpdateCamera( void );
void UpdateCamera( const Vector3f& coords );
private:
void InitCamera( void );
Matrix3fv* mRotation;
Vector3f* mPosition;
float mAngle;
};
}
I've even tried initializing the default constructor of CoordinateObject
's ctor in any deriving class' initialization list, but honestly I doubt that makes a difference.
Example
(from Shape.h)
Shape::Shape( Vector3f& center, float radius )
: CoordinateObject(),
mRadius( radius )
{
InitShape( center );
}
As you can see, CoordinateObject
's constructor is called here, in the initialization list, even though it is default.
I'm at a loss as to what to do.
Halp?
Update
I had it compiling under Debug in MinGW, but now that I switched to Release (for whatever reason), it worked!
Why it worked this way, I'm not quite sure. Maybe a glitch somehow with Qt (or MinGW, even)?