STL problems with VC6

Started by
5 comments, last by MaulingMonkey 19 years, 7 months ago
In a class that has only static members and functions (how do you call that?), I have a member of type std::list<std::string>. On exiting my application I sometimes get a 'Damage after normal block' error. The offending line is in the code below:

//dxgame.h
typedef std::string tDXString;
typedef std::list<tDXString> tDXStringList;

class DXGame
{
    private:
        static tDXStringList consoletext;		
        ...
    public:
        static void AddConsoleLine(const tDXString pLine);
        static void DrawConsole();
        ...
};

//dxgame.cpp
tDXStringList DXGame::consoletext; // Init static members
...

void DXGame::AddConsoleLine(const tDXString pLine)
{
    consoletext.push_back(pLine); // 'Damage after normal block' error on exit
}

Searching teh Google made me guess it may have to do with a bug in the STL implementation of VC6. Can anyone confirm this or is it just a nasty error in my code? If I use std::list<char*> or never call AddConsoleLine() the code will run fine. Thanks in advance. Edit: fixed source tags
Advertisement
I see no error, I'm guessing it's an STL bug.

As a small comment, you should change the definition of AddConsoleLine to:

static void AddConsoleLine(const tDXString & pLine);


as this will prevent an extra string copy if passing a std::string/tDXString as the argument, and it will still work passing a value to be converted, even if it is a literal, due to the const defintion (aka this will still work:)

DXGame dxGame;tDXString myString;dxGame.AddConsoleLine( "I like pie" ); //converts to const tDXStringdxGame.AddConsoleLine( myString ); //passes by reference, so no copy needed.


and you will still be able to take, say, the return of functions:

tDXString SomeFunction ( void ) { return "pie"; }dxGame.AddConsoleLine( SomeFunction() );
Thanks so far, I started out with passing by reference but that made no difference.
Also, the class isn't meant to be instanced (sp?) but will be used globally, i.e. DXGame::AddConsoleLine("blah") etc.
Would that make any difference?
Okay, I installed STLport and it seems to have solved the problem. So after all the VC6 implementation was broken anyway (as I've heard before).
Quote:Original post by Prototype
In a class that has only static members and functions (how do you call that?)...
A namespace. Or rather, it should be.
Quote:Original post by Oluseyi
A namespace. Or rather, it should be.

Good point. I thought about that but it needs to access a private function of another class through friendship (users shouldn't be able to call that function directly). Is this possible in another way?
Quote:Original post by Prototype
Thanks so far, I started out with passing by reference but that made no difference.


It was an optimization note - it should make a minor speedup to your code when the argument is a std::string.

Quote:Original post by Oluseyi
Quote:Original post by Prototype
In a class that has only static members and functions (how do you call that?)...
A namespace. Or rather, it should be.

Unless it's meant to be a template argument. An allocator, for example. Last I checked, there was no template argument type for namespaces ;_;.

That said, you're definately right for this case - if DXGame isn't meant to be instantiated, it should probably be a namespace.

This topic is closed to new replies.

Advertisement