c++ - deque.push_front() giving error "expression must have class type" -
i trying initialize deque pointers user defined struct, tile, in order eliminate unnecessary copying.
my code looks this:
tile *start = new tile(0,0,0, 'q', nullptr); deque<tile*> search(); search.push_front(start);
the above code located in main.cpp.
the tile struct looks this, , contained in 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){} };
the layout of program follows:
main.cpp: includes "io.h"
io.h: includes "hunt.h", various standard libraries
hunt.h: includes vector, deque, tile struct
however, getting error in main.cpp when try push_front(start): expression must have class type." wasn't sure if possible fault in #includes causing error, please let me know if case. otherwise, not entirely sure how fix error.
thanks in advance!
when write
deque<tile*> search();
you aren't declaring deque<tile*>
named search
, using default constructor. instead, c++ interprets function declaration function named search
takes no parameters , returns deque<tile*>
. can't call push_front
on function, hence error.
to fix this, either remove ()
declaration of variable, or replace them {}
(if you're using c++11-compliant compiler). cause c++ (correctly) interpret want declare variable.
hope helps!
Comments
Post a Comment