Solved

Initializing a const in the view from Doc

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 51
Question regarding Copy/Paste 16 96
ffmpeg - "rtsp://...... Operation not permitted" 4 86
wait notify demo infinite loop 3 124
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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