confusion of error

I ma not sure why i would be getting this error. After awhile of not figuring it out, i figured i would ask the forums. I am not sure if i acciedently deleted a character or something as i cannot figure out why this error would be present.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

class Rect{
    public:
        sf::RectangleShape rect;
        bool moving_up = false, 
            moving_down = false,
            moving_right = false,
            moving_left = false; 
        Rect(){
            rect.setSize(sf::Vector2f(100,100));
            rect.setPosition(sf::Vector2f(10,10));
            rect.setFillColor(sf::Color::Red);
        }
};

class Control{
    public:
        sf::RenderWindow window;
        Rect obj;
        
        Control(){
            window.create(sf::VideoMode(600,400), "Title");
            window.setKeyRepeatEnabled(false);
        }
        
        void update(sf::Event event){
            window.clear(sf::Color::Black);
            window.draw(obj.rect);
            window.display();
        }
        
        void input_handler(sf::Keyboard::Key key, bool is_pressed){
            if (key == sf::Keyboard::W)
                obj.moving_up = is_pressed;
            else if (key == sf::Keyboard::S)
                obj.moving_down = is_pressed;
            else if (key == sf::Keyboard::D)
                obj.moving_right = is_pressed;
            else if (key == sf::Keyboard::A)
                obj.moving_left = is_pressed;
        }
        
        void event_handler(sf::Event event){
            while(window.pollEvent(event))
                if (event.type == sf::Event::Closed)
                    window.close();
                else if (event.type == sf::Event::KeyPressed)
                    input_handler(event.key.code, true);
                else if (event.type == sf::Event::KeyReleased)
                    input_handler(event.key.code, false);
            }
        }
        
        void run(){
            while (window.isOpen()){
                sf::Event event;
                event_handler(event);
                update(event);
            }
        }
};

int main(){
    Control app;
    app.run();
}


the error i get is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
test.cpp:55:9: error: expected ‘;’ after class definition
         }
         ^
test.cpp: In function ‘void run()’:
test.cpp:58:20: error: ‘window’ was not declared in this scope
             while (window.isOpen()){
                    ^
test.cpp:60:36: error: ‘event_handler’ was not declared in this scope
                 event_handler(event);
                                    ^
test.cpp:61:29: error: ‘update’ was not declared in this scope
                 update(event);
                             ^
test.cpp: At global scope:
test.cpp:64:1: error: expected declaration before ‘}’ token
 };
 ^
Last edited on
ok figured it out. After posting i reviewed the code one last time, and I must of accidently deleted a bracket somehow:
while(window.pollEvent(event))
to
while(window.pollEvent(event)){
Last edited on
Topic archived. No new replies allowed.