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
Solved

Getting CRichEditCtrl

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

790 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