Solved

Getting CRichEditCtrl

Posted on 2008-06-22
3
254 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:rickatseasoft
  • 2
3 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21842641
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();
0
 

Author Comment

by:rickatseasoft
ID: 21842731
It certainly works as you suggest, but I wonder if you hi\ave the time to explain why?
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 21842780
Well, as I stated, you cannot declare an "unreferenced" reference in C++.
It has to be referenced inmediately. It doesn't work like pointers that you can declare without pointing to anything.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now