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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -