Solved

Initializing a const in the view from Doc

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 67
Complete beginner needs help making a cron job 9 116
unable to delete all specified values regedit 38 389
Message not shown 5 49
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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