• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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
  • 2
1 Solution
Jaime OlivaresSoftware ArchitectCommented:
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

or even you can use directly without using a variable:
rickatseasoftAuthor Commented:
It certainly works as you suggest, but I wonder if you hi\ave the time to explain why?
Jaime OlivaresSoftware ArchitectCommented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now