c++ - Vector Public in Class - Can't Use in Implementation? -
here's situation. have class in have defined vector publicly, below:
class trackobjects { public: vector<movingobj> movingobjects; ...
etc.
it has constructor , everything. have separate .cpp file implementations i'm trying use vector , methods on vector. 1 example, it's part of condition in function so:
if (movingobjects.locx >= x1)
...
etc.
it tells me movingobjects undeclared, , first use function. it's not function, , knowledge, haven't called one/tried use one.
can suggest why might getting error?
edit: locx public variable in class movingobj. trackobj class creates vector objects movingobj creates. sorry, should've specified that. so:
class movingobj {
public:
movingobj(int inid, int inlocx, int inlocy, int inwidth, int inheight);
int id, locx, locy,width,height;
based on telling us, proper way access locx along lines of:
trackobjects objs; objs.movingobjects[15].locx = 123.45;
or, maybe:
if(objs.movingobjects[15].locx >= 15) { //do }
you can encapsulate access method in trackobjects (put in trackobjects.cpp implementation):
bool trackobjects::testlocx(int pos) { if(movingobjects[pos].locx>=15) return true; return false; };
Comments
Post a Comment