Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ game programming

Name: Anonymous 2010-08-25 7:45

So I have a hopefully simple problem.

I have a mainWindow and Window class in my C++ project. For debugging purposes, I want to add 20 points to the player's score every second.

So, in my main loop, I do:


if(event.type == SDL_KEYDOWN)
{
            window.getGUI().addPoints(20);
}


The getGUI() is just a normal getter function of type GUI that returns the gui object from the Window class. However, it doesn't update the score correctly. If I do a direct gui.addPoints(20); in the Window class, the score does update correctly, so I'm assuming it's a problem with accessing the gui object from outside the Window class. Any ideas?

Name: Anonymous 2010-08-25 10:38

>>10
There's only one thing I don't agree with in that link:

you can store pointers rather than objects in an STL container
This is only valid for Google because they disable exceptions. It isn't exception-safe to do this.

Your best bet if you want to do this is to enable C++0x and use unique_ptr<>. If you can't, add Boost and use the pointer containers. If you can't use Boost, use shared_ptr<>. And if you don't have access to even that, well, you're fucked. You've got to write your own smart pointer or pointer container, and you're probably going to introduce bugs into it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List