Solved

Initializing a const in the view from Doc

Posted on 2008-10-15
1
187 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 31

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 29
Whole sheet autoscrub still needed 19 48
maxBlock challenge 30 112
Making an alias 7 82
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

20 Experts available now in Live!

Get 1:1 Help Now