Hi,

Please may I have your help on this one. The error is:
1>------ Build started: Project: DXTB 17, Configuration: Debug Win32 ------
1> Main.cpp
1> _MyDebug Defined...
1> _Main Defined...
1> _CApplication Defined...
1> _CSpriteManager Defined...
1> _CSprite Defined...
1> __CStats Called...
1> _CStats Defined...
1> _CVector3F Defined...
1> _CText Defined...
1> _CFile Defined...
1> _CMap Defined...
1> _CTile Defined...
1> _CCollisionManager Defined...
1> _CEntity Defined...
1> _CCamera2D Defined...
1> _TPhysics Defined...
1> __CStats Called...
1>d:\code\dx tuts\projects\dxtb_curr\dxtb 17_2\dxtb 17\ccamera2d.h(28): error C2504: 'CStats' : base class undefined

I have header gaurds and pertinent forward declarations where neccassary. I am defining CStats as a base class of CSprite though CSpriteManager. Also as a base class of CCamera2D. Before you say - there are no semicolons missing!

This is CStats:

#pragma message("__CStats Called...")

#ifndef CStats_h
#define CStats_h

#include "MyDebug.h"
#ifdef PRAMGA_MESSAGE_DEFINED
#pragma message("_CStats Defined...")
#endif

#include <d3dx9.h>
#include "CVector3F.h"

class CVector3F;

class CStats
{
public:
    CStats(void);
    ~CStats(void);

    // Coordinates
    CVector3F* m_pWorldPosition;
    CVector3F* m_pScreenPosition;

    /*SNIP*/
};

#endif // CStats

This is CCamera2D that the error is produced by:

#ifndef CCamera2D_h
#define CCamera2D_h

#include "MyDebug.h"
#ifdef PRAMGA_MESSAGE_DEFINED
#pragma message("_CCamera2D Defined...")
#endif

#include <d3dx9.h>

#include "TPhysics.h"
#include "CStats.h"
#include "CEntity.h"

class CStats; //<== May not need to be

class CCamera2D: public CStats
{
public:
    CCamera2D(void);
    ~CCamera2D(void);

    enENTITYTYPE m_enEntityType;

    void ApplyPhysics(void);

    // Set velocity for a direction until vel limit is reached
    inline void MoveLeft(void)  { m_Physics.VelocityLeft(); }
    inline void MoveRight(void) { m_Physics.VelocityRight(); }
    inline void MoveUp(void)    { m_Physics.VelocityUp(); }
    inline void MoveDown(void)  { m_Physics.VelocityDown(); }

    TPhysics<CCamera2D> m_Physics;

    /*SNIP*/
};

#endif // CCamera2D_h

I think that CSpriteManager defines CStats through CSprite within the translation unit and by the time it comes to CCamera2D, to inherit CStats, the header guards prevent redefinition. The project, which is too big to post it all, was working before I read this article on headers&includes and decided to move all my includes to thier headers. What can I do...? Thanks in advance...!

You just declared the structure of the class, its ctor and dtor and some data members. Does your project files include a source file that will define the class?

Thank you for your kind reply.
I have finally sorted. btw I didn't post the source. The solution involved carefully looking at the current translation unit and seeing when the undefined class is first (pre)defined. Then open the class and put its include of the class into the implementation instead of the header. Now when it comes around the culprite class to ask for the header it is not yet defined. So it can now define it for itself. I hope I explained it ok? so in the above example I put the #include "CStats.h" called by CSprite.h into the implementation of the CSprite source and it works ok. I do this for each base class undefined error. So some things get included in the header and some in the source.

Edited 3 Years Ago by Elixir42: accidentally pressed submit

This question has already been answered. Start a new discussion instead.