Hello,
I would like to know what is wrong in this code:
CClientEngine::CClientEngine(MClientObserver& aObserver)
:CActive(CActive::EPriorityStandard )
{
iObserver=aObserver; //****
iPostData=NULL;
iRunning=EFalse;
}
because i have the following error: '&' reference member 'iObserver' is not initialized.
Why this line (****) doesn't initialize iObserver? thanks
References and constants need to be initialized when they are declared and can not be changed later. When used as class members they must be initialised before complete construction of the class i.e. in initialization list. This is because default constructors of stack based members are called before the constructor and thats where they get initialised. Since they can not be changed once initialized any attempt of initializing them in constructor results in comile error.
Forum posts: 683
References must be initialized before any code is executed; this is plain C++. Thus you must do it in the constructor's initialziation list:
ClientEngine::CClientEngine(MClientObserver& aObserver):CActive(CActive::EPriorityStandard ), iObserver(aObserver)
{
iPostData=NULL;
iRunning=EFalse;
}
The same applies to const data member variables.
Forum posts: 2
References and constants need to be initialized when they are declared and can not be changed later. When used as class members they must be initialised before complete construction of the class i.e. in initialization list. This is because default constructors of stack based members are called before the constructor and thats where they get initialised. Since they can not be changed once initialized any attempt of initializing them in constructor results in comile error.
Forum posts: 26
Thanks!