私は完全に理解できなかったか、非常に奇妙な問題を抱えています。それはおそらく最初のものですが、私は午後全体をグーグルで過ごしましたが成功しなかったので、ここに行きます...
私はScheduleというクラスを持っています。これは、メンバーとしてRoomのベクトルを持っています。ただし、cmakeを使用して、または手動でコンパイルすると、次のようになります。
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)->Schedule::_sched’, which is of non-class type ‘int’
schedule.cpp:13: error: ‘r’ was not declared in this scope
関連するコードは次のとおりです。
#include <vector>
#include "room.h"
class Schedule
{
private:
std::vector<Room> _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<nrooms;i++)
{
Room r(ndays,ntslots);
_sched.push_back(r);
}
}
理論的には、g++はそれを含むクラスの前にクラスをコンパイルする必要があります。ここには循環依存関係はありません。すべて単純なものです。私はこれに完全に困惑しています。それは私が何かを逃しているに違いないと私に信じさせるものです。:-D
編集:以下のコメントから
の内容:room.h
#include <vector>
#include "day.h"
class Room
{
private:
std::vector<Day> _days;
public:
Room();
Room(int ndays, int length);
~Room();
};