Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ class is not being included properly
    primarykey
    data
    text
    <p>I have a problem which is either something I have completely failed to understand, or very strange. It's probably the first one, but I have spent the whole afternoon googling with no success, so here goes...</p> <p>I have a class called Schedule, which has as a member a vector of Room. However, when I compile using cmake, or even by hand, I get the following:</p> <pre><code>In file included from schedule.cpp:1: schedule.h:13: error: ‘Room’ was not declared in this scope schedule.h:13: error: template argument 1 is invalid schedule.h:13: error: template argument 2 is invalid schedule.cpp: In constructor ‘Schedule::Schedule(int, int, int)’: schedule.cpp:12: error: ‘Room’ was not declared in this scope schedule.cpp:12: error: expected ‘;’ before ‘r’ schedule.cpp:13: error: request for member ‘push_back’ in ‘((Schedule*)this)-&gt;Schedule::_sched’, which is of non-class type ‘int’ schedule.cpp:13: error: ‘r’ was not declared in this scope </code></pre> <p>Here are the relevant bits of code:</p> <pre><code>#include &lt;vector&gt; #include "room.h" class Schedule { private: std::vector&lt;Room&gt; _sched; //line 13 int _ndays; int _nrooms; int _ntslots; public: Schedule(); ~Schedule(); Schedule(int nrooms, int ndays, int ntslots); }; Schedule::Schedule(int nrooms, int ndays, int ntslots):_ndays(ndays), _nrooms(nrooms),_ntslots(ntslots) { for (int i=0; i&lt;nrooms;i++) { Room r(ndays,ntslots); _sched.push_back(r); } } </code></pre> <p>In theory, g++ should compile a class before the one that includes it. There are no circular dependencies here, it's all straightforward stuff. I am completely stumped on this one, which is what leads me to believe that I must be missing something. :-D</p> <p>Edit:<br> The contents of <code>room.h</code> from the comments below:</p> <pre><code>#include &lt;vector&gt; #include "day.h" class Room { private: std::vector&lt;Day&gt; _days; public: Room(); Room(int ndays, int length); ~Room(); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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