Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CMap and STL coexistence...

Posted on 2000-03-31
5
Medium Priority
?
269 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

885 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