Solved

Initializing a const in the view from Doc

Posted on 2008-10-15
1
186 Views
Last Modified: 2013-11-20
Hiya

I have an MFC SDI application.

In the View I have a variable

const CString ViewMessage

I want to initialize this variable from a value in the Doc e.g. DocMessage.

As the variable is const I have to initialize it in the constructor list. How do I do this?

I tried adding

ViewMessage(GetDocument()->DocMessage)

to the View initialization list and it compiles. Unfortunately, when I run it, it just causes an assertion and loads of memory leaks.

Can anybody help?

John
 
0
Comment
Question by:IssacJones
1 Comment
 
LVL 30

Accepted Solution

by:
Zoppo earned 250 total points
ID: 22720871
Hi IssacJones,

in general it's correct to initialize const members in the initialization list - IMO the problem is that 'GetDocument' doesn't return a valid documen pointer (I guess it returns NULL) since the CView::m_pDocument (which is returned by GetDocument) isn't yet initialized.

Unfortunateley I don't know a workaround for this except not using const for that member ...

ZOPPO
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

24 Experts available now in Live!

Get 1:1 Help Now