Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CMap and STL coexistence...

Posted on 2000-03-31
5
Medium Priority
?
268 Views
Last Modified: 2013-11-20
I'm trying to make use of a CMap in a project which uses STL (set, multiset). The problem is that the CMap constructor never gets called for the static CMap member variable.

in the application header:
     COXSound m_oxSound;

in the header of the COXSound class:

protected:
     static CMap<COXSound*, COXSound*, DWORD, DWORD> m_allSoundObjects;

in the COXSound impl. file:

#include "OXSound.h"
IMPLEMENT_SERIAL(COXSound, CObject, 1)

/////////////////////////////////////
// Definition of static members
CMap<COXSound*, COXSound*, DWORD, DWORD> COXSound::m_allSoundObjects;


in the application's InitInstance():

     m_oxSound.SetCallbackWnd(m_pMainWnd);

     // can this machine playback waves?
     if (m_oxSound.CanPlay())
     {
          // call constructor just to init member stuff...
          COXSound* pSound = new COXSound;
          delete pSound;
          pSound = NULL;
   
         if (m_oxSound.Open(_T("thx.wav")))
         {
          m_oxSound.Play(FALSE, TRUE);
         } // end if
     } // end if

The code in the COXSound constructor gets called without the CMap constructor having been called, and the code ASSERTs within afxtempl.h attempting to do the SetAt() call.

Is it possible that STL is interfering with this, or what other things should I look for??


0
Comment
Question by:captainkirk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 2674198
Since m_allSoundObjects is a static member variable, the constructor is called at the very beginning of the program. The constructor should have been called. There is something else wrong. Give us more information.
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2687089
chensu - the CRT code which calls the constructors specific to the app does not recognize that the CMap constructor needs to be called and bypasses it. If I take the m_oxSound variable out and any references to it, then the CMap constructor gets called. I can post the sound player code here if you want - it's a bit lengthy...
0
 
LVL 4

Accepted Solution

by:
abancroft earned 600 total points
ID: 2687379
I wonder if it has anything to do with you CWinApp class being a global member at file scope...?

Can you replace CMap with std::map?
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2687812
abancroft - ya know, replacing the CMap might be worth a try - I hadn't thought of that, but if it has anything to do with STL interference, that just might make it go away...
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2701320
I haven't actually tried the solution - I've been busy on other aspects of my project, but I'm pretty confident that the suggestion will work...
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

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…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

705 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