[Visual C++ 2008 Express] Porting issues

Started by
5 comments, last by rsborl 14 years, 11 months ago
I made a game using Dev-C++, and currently transferred it over to Visual C++ 2008 Express. The code worked fine before. How I transferred it was to simply move over all the files and include them to the VC++ project. For some reason, I am getting a "Access violation writing location 0x00000000" error, even when that part of my program does not use pointers. VC++ pointed the error in a low-level system function, so I moved up the stack frame and traced the cause to my program: EventList.h

class EventList
{
public:
protected:

  static void post(string sSource, string sMessage, string sEventLabel);
  static list<string> s_events;
};
EventList.cpp (holds the offending function)

#include "EventList.h"

list<string> EventList::s_events;

void EventList::post(string sSource, string sMessage, string sEventLabel)
{
  s_events.push_back(sSource + sEventLabel + sMessage);
}
The post function causes the error. If I comment out that line, the program continues to execute, but runs into another similar error in another function. I am wondering, is the problem in the code or a setting in VC++?
Advertisement
When you get the access violation is it before or after main() begins?
Quote:Original post by SiCrane
When you get the access violation is it before or after main() begins?


Before, in the global namespace, above the main function.
It sounds like your program relied on s_events being initialized before being used by other static objects. Unfortunately, C++ gives no guarantee as to the order of initialization of objects of static storage duration in different translation units. So basically, it sounds like it's a problem with your code.
Quote:Original post by SiCrane
It sounds like your program relied on s_events being initialized before being used by other static objects. Unfortunately, C++ gives no guarantee as to the order of initialization of objects of static storage duration in different translation units. So basically, it sounds like it's a problem with your code.


Hmm, so the program might have been attempting to use s_events before it was even placed in memory? Because, in my case, s_events doesn't need any initialization; it just needs to be created and its constructor called.
Having its constructor called is initialization.
Quote:Original post by SiCrane
Having its constructor called is initialization.


I see. Thanks very much for the help.

This topic is closed to new replies.

Advertisement