Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - arkan01

Pages: [1]
1
Graphics / Re: String error on a constructor of a class
« on: September 14, 2016, 06:12:41 pm »
Thank you for the fast reply.

Following your instruction, i runned it on debug mode, and now i understand the problem.
Again thank you for this explanation. :)

2
Graphics / String error on a constructor of a class
« on: September 14, 2016, 04:48:41 pm »
I recently started to learn c++, so i'd like to have detailed explanations if you can. :)
(If i posted in the wrong section, i'm sorry)

Here's the code:

Player.h:
class Player {
public:
        Player(std::string, sf::Color);
        void Update();
        void Draw(sf::RenderWindow*, sf::RenderStates);

private:
        ...
        sf::Text nickname;
        sf::Font font;
}

Player.cpp
Player::Player(std::string _nickname, sf::Color color) {
...
        nickname.setFont(font);
        nickname.setString(_nickname);
        nickname.setCharacterSize(12);
        nickname.setFillColor(sf::Color(255, 255, 255));
}

void Player::Draw(sf::RenderWindow* window, sf::RenderStates states) {
        window->draw(_player, states);
        window->draw(nickname, states);
}

Here's the problem:

Main.cpp:
int main() {
        ...

        std::vector<Player> players;

        while (window.isOpen()) {

                std::string nickname; std::cin >> nickname;
                players.push_back(Player::Player(nickname, sf::Color(102, 0, 0)));

                window.clear();
       
                window.draw(cursor, states);
                for (auto player : players)
                        player.Draw(&window, states);
                window.display();
         }
}

When i try to write the nickname on the console, and press ente it gives me the following error:
"Debug assertion failed! Expression: map/set insert iterator out of range".

Thanks in advance.

Pages: [1]