C++ Can't pass reference to a pointer when the function arg type is class interface -


i have interface looks :

class igameobject { public:     virtual ~igameobject(){}     virtual void notify(massage message) = 0;     virtual void sendmessages() = 0; };  class winframeobj :public sprite , public basegameobject<winframeobj> {     public:          winframeobj();         virtual ~winframeobj(){};         static winframeobj* createinternal();                 void notify(massage message);  };  template<typename t> class basegameobject : public igameobject {     public:         basegameobject(){};          virtual ~basegameobject(){};          static t* createobj()         {             return t::createinternal();         }  };  // simple catch class  typedef std::map<gameobjecttype, igameobject*> componentsmap; class componentmadiator{    ....  .... void componentmadiator::register(const gameobjecttype gameobjecttype,igameobject*& gameobj) {    componentsmap[gameobjecttype] = gameobj;  // std map } ... ...  } 

now in code in main class

winframeobj* m_pmainwindowframeobjcenter ; // defined in header memeber  pmainwindowframeobjcenter  = winframeobj::createobj(); componentmadiator::instance().register(main_win_frame,pmainwindowframeobjcenter);  

im getting error:

error c2664: 'componentmadiator::register' : cannot convert parameter 2 'winframeobj *' 'igameobject *&' 

i need componentmadiator::register method generic there allot of objects type igameobject , have reference pointer

update
reason keep data store in map persistent on time . if pass pointer , try call object :

igameobject* componentmadiator::getcomponentbyobjtype(gameobjecttype  gameobjecttype) {     return componentsmap[gameobjecttype]; } 

the data in return object got lost.

your problem function

void componentmadiator::register(     const gameobjecttype gameobjecttype,     igameobject*& gameobj) 

it should accept non-reference

componentmadiator::register(       const gameobjecttype gameobjecttype,        igameobject *object) 

or accept const reference pointer.

the underlying issue can't decay referece temporary non-const reference.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -