Jump to content
  • Advertisement
Sign in to follow this  
Prototype

STL problems with VC6

This topic is 5475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 tDXString
dxGame.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() );

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!