【发布时间】:2014-02-05 22:27:35
【问题描述】:
我正在尝试使用指向用户定义结构 Tile 的指针初始化双端队列,以消除不必要的复制。
我的代码如下所示:
Tile *start = new Tile(0,0,0, 'q', nullptr);
deque<Tile*> search();
search.push_front(start);
以上代码位于main.cpp中。
Tile 结构看起来像这样,并且包含在hunt.h 中:
struct Tile
{
int row; int col; int farm;
char tile;
Tile * added_me;
Tile(int f, int r, int c, char t, Tile * a) :
farm(f), row(r), col(c), tile(t), added_me(a){}
};
我的程序布局如下:
main.cpp:包括“io.h”
io.h:包括“hunt.h”,各种标准库
hunt.h:包括vector、deque、Tile struct
但是,当我尝试 push_front(start) 时,main.cpp 中出现错误:表达式必须具有类类型。”我不确定 #includes 中的可能错误是否导致了此错误,所以请如果是这种情况,请告诉我。否则,我不完全确定如何解决此错误。
提前致谢!
【问题讨论】:
标签: c++ visual-c++ stl deque