Solved

Getting CRichEditCtrl

Posted on 2008-06-22
3
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why isn't object file created? 6 107
Installshield for Embarcadero EX 10.1 Berlin 4 92
designing in object programming 12 132
Authenticate using sesu from script 7 159
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

739 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