Hello everyone,
I am writing a fairly simple program that animates a sprite using SDL, and cannot get past the errors "'CAnim' does not name a type" and "field 'Anim_Rock' has incomplete type"; although I have searched for an answer extensively on this forum and others, I'm still at a dead standstill on this. I don't get both errors at once, I get "incomplete type" when attempting a forward declaration fix.
To be more specific, here is my code... I am using Code::Blocks and MingW. I have cut out any SDL and have cut it down to the base problem, and nothing else. This code is, in its entirety, a separate program I wrote to attempt a debug, but to no avail.
CBase.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#ifndef CBASE_H_INCLUDED
#define CBASE_H_INCLUDED
#include "CAnim.h"
class CBase
{
private:
CAnim Anim_Rock;
public:
CBase();
};
#endif
|
CAnim.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#ifndef CANIM_H_INCLUDED
#define CANIM_H_INCLUDED
#include "CBase.h"
class CAnim
{
private:
int TotalFrames;
public:
CAnim();
};
#endif
|
CBase.cpp
1 2 3 4 5 6
|
#include "CBase.h"
CBase::CBase()
{
}
|
CAnim.cpp
1 2 3 4 5 6
|
#include "CAnim.h"
CAnim::CAnim()
{
TotalFrames = 2;
}
|
A workaround I have already tried and failed is to affix a forward declaration to CBase.h, which is when I get the error "incomplete type":
1 2 3 4 5 6 7 8 9
|
#ifndef CBASE_H_INCLUDED
#define CBASE_H_INCLUDED
#include "CAnim.h"
class CAnim;
class CBase
//Prototypes and such here
|
Ultimately, I have been able to get the program to run if I place both class declarations into the same header file (only if CAnim is before CBase, however). Forward declarations are not working for me, and I cannot keep it this way because it will create some problems as I introduce more classes into my program.
An answer would be greatly appreciated, as I have been dealing with this issue myself for a few frustrating hours; I have the annoying feeling that I'm making a very minor mistake.