Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems inheriting from a class in the same namespace in C++
    text
    copied!<p>I was happily working in C++, until compilation time arrived.</p> <p>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:</p> <pre><code>namespace N{ class Base{ }; class Derived: public Base{ }; } </code></pre> <p>However, g++ (maybe linker) keeps telling me:</p> <pre><code>Derived.hpp:n: error: expected class-name before ‘{’ token </code></pre> <p>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!</p> <p>"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:</p> <pre><code>#include "Base.hpp" namespace N{ class Base; class Derived: public Base{ }; } </code></pre> <p>And now g++ complains:</p> <pre><code>Derived.hpp:n: error: invalid use of incomplete type ‘struct N::Base’ </code></pre> <p>So, I got lost here. Please help me, I will apreciate it a lot. :)</p> <p>(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 :).</p> <p><strong>Edit:</strong> A more exact representation of my files is:</p> <pre><code>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() {} }; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload