Link to home
Start Free TrialLog in
Avatar of rickatseasoft
rickatseasoft

asked on

Getting CRichEditCtrl

I am trying to get a CRichEditCtrl by creating a member variable

CRichEditCtrl &m_RichCtrl

and then call m_RichCtrl=GetRichEditCtrl();

The compiler complains:error C2758: 'm_RichCtrl' : must be initialized in constructor base/member initializer list

Can anyone explain why and how to fix it?

Thanks, Rick
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

you cannot declare a reference and assign it later. I suggest to declare and assign ad hoc as a local variable, like in:

// declare locally
CRichEditCtrl &richCtrl=GetRichEditCtrl();
// use it here
richTrl.DoSomething();

or even you can use directly without using a variable:
GetRichEditCtrl().DoSomething();
Avatar of rickatseasoft
rickatseasoft

ASKER

It certainly works as you suggest, but I wonder if you hi\ave the time to explain why?
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial