i have main class that i like to pass its pointer reference to on of the objects i creating but it gives me error :
Error 1 error C2664: 'GameController::GameController(GameLayer *&)' : cannot convert parameter 1 from 'GameLayer *const ' to 'GameLayer *&'
what i have in the GameLayer ( the main object )
m_pGameController = new GameController(this);
and in the GameController i have this constructor
GameController(GameLayer*& GameLayer)
{
setGameLayer(gameLayer); // to GameLayer memeber )
}
the resone is i need to be able to modify the data in GameLayer from GameController (GUI stuff)
First, the type of
thiscould beGameLayer * constorconst GameLayer * constdepending upon whether the member function isconstor not. But, it is aconstpointer.Having said that, a reference to a pointer
type *&refmeans indicates that you will be modifying the pointer, the object which it is pointing to."Since, this pointer is a constant pointer you cannot assign that to a non-const pointer(GameLayer * p)" in the context of references.
In case of references to pointer, you cannot assign to a reference which will modify the value in
this. You cannot assign it to a reference to anon-constpointer(GameLayer *&p), but you can assign a reference to aconstpointer i.e.GameLayer *const &p.So, changing the constructor to
GameController(GameLayer * const & gameLayer)should work.But I don't see any use of it here currently.
And if you're calling from a
constmember function thenthishas the typeconst *constso you will have to change it toGameController(const GameLayer * const & gameLayer).