Solved

Getting CRichEditCtrl

Posted on 2008-06-22
3
256 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 62
Detect file exist or not 3 157
Dialogbox API leak? 18 95
JQuery serialize and unserialize 8 84
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

777 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