I was happily working in C++, until compilation time arrived.
I've got several classes inside some namespace (let's call it N); two of these classes correspond to one base class, and other derived from it. Each class has its own pair of .hpp and .cpp files; I think it'd look like:
namespace N{
class Base{
};
class Derived: public Base{
};
}
However, g++ (maybe linker) keeps telling me:
Derived.hpp:n: error: expected class-name before ‘{’ token
It doesn't recognize Base as a class, even when I have correctly #include'ed the hpp file corresponding to its definition to Derived's .hpp!
"It's something with #includes", I thought, since these classes' .hpps are #included in other files, so I added this to Derived declaration in Derived.hpp:
#include "Base.hpp"
namespace N{
class Base;
class Derived: public Base{
};
}
And now g++ complains:
Derived.hpp:n: error: invalid use of incomplete type ‘struct N::Base’
So, I got lost here. Please help me, I will apreciate it a lot. :)
(By the way, I'm rather experienced in Python, not C++, so this issues are really strange to me. Also, I changed classes' names and stuff :).
Edit: A more exact representation of my files is:
File Pieza.hpp
-----------------------
#include "Celda.hpp"
namespace Reglas
{
class Pieza
{
public:
Pieza() {}
virtual ~Pieza() {}
private:
Celda *c;
};
}
File Jugador.hpp
-----------------------
#include "Jugada.hpp"
#include "Excepciones.hpp"
#include "Pieza.hpp"
namespace Reglas
{
//compiler asked for these :S
class Celda;
class Tablero;
class Jugador : public Pieza
{
public:
Jugador() {}
virtual ~Jugador() {}
};
}