Passing a vector of object pointers to a class (C++) -


i have vector of object pointers.

std::vector<myobject *> listofobjects; 

and want pass them object needs access them.

when try following:

class needsobjects  {  public:     needsobjects(std::vector<myobject *> &listofobjects)  private:     std::vector<myobject *> &listofobjects; }; 

and initialize vector in initialization list following errors:

'myobject' not declared in scope template argument 1 invalid template argument 2 invalid 

what doing wrong? want pass vector needsobjects class.

you use pointers object, don't have define complete object structure, declare in file before using it:

class myobject; // pre declaration, no need know size of class class needsobjects  {  public:     needsobjects(std::vector<myobject *> &listofobjects)  private:     std::vector<myobject *> &listofobjects; }; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -