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

Author Topic: Getting confusing compiler error when trying to color a rectangle.  (Read 1237 times)

0 Members and 1 Guest are viewing this topic.

C++AndChill

  • Newbie
  • *
  • Posts: 1
    • View Profile
int main(){

    sf::RenderWindow window(sf::VideoMode(800, 600), "Game");

    sf::RectangleShape rectangle(sf::Vector2f(100, 50));
    shape.setFillColor(sf::Color(211, 211, 211));

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {

            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color::Black);

        window.draw(shape);

        window.display();
}

    sf::Music music;

    if (!music.openFromFile("audio/ambwon.ogg")){}

    music.setVolume(50);
    music.play();

}
 

My compiler, GNU GCC, gives me "error: 'shape' was not declared in this scope" on line 17 (shape.setFillColor(sf::Color(211, 211, 211));.

shape.setFillColor worked just fine earlier, so why is it throwing errors all of a sudden?  ???

Any insight would be greatly appreciated.
« Last Edit: August 06, 2018, 01:00:57 pm by C++AndChill »
I spend my time programming and chilling.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting confusing compiler error when trying to color a rectangle.
« Reply #1 on: August 06, 2018, 01:31:15 pm »
Because your variable is named "rectangle", not "shape".
Laurent Gomila - SFML developer

 

anything