Variable or field declared void

Hello, I have been learning c++ and sfml and I've been learning as i go along so i don't get bored. I have run into an issue with a class that i have created. It's my first attempt at creating a class so i guess my approach is wrong.

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
#include <sfml/graphics.hpp>
     
using namespace std;
     
class game{    /**< This Class handles running the game, drawing the window
                        and proccessing the events */
     
public:
        void    run();
     
private:
           void processEvents();
           void update();
private:
            sf::RenderWindow mWindow;
            sf::CircleShape mPlayer;
void run{
            while(mWindow.isOpen()){
                processEvents();
                update();
                render();
                }
            };
void processEvents{
        sf::Event event;
     
        while(mWindow.pollEvent(event)){
            if(event.type == sf::Event::Closed){
                mWindow.close();
                }
            }
        };
void update{
        mwindow.clear
       
        mWindow.draw(mPlayer);
        mwindow.display();
        };
};
     
     
int main(){
game game;
game.run();
     
return 0;
}



my error:
1
2
3
C:\Users\adil\Documents\Coding!\SFML GAME\main.cpp:23:9: error: variable or field 'run' declared void
C:\Users\adil\Documents\Coding!\SFML GAME\main.cpp:32:5: error: variable or field 'processEvents' declared void
C:\Users\adil\Documents\Coding!\SFML GAME\main.cpp:38:5: error: variable or field 'update' declared void
Last edited on
The private partition is for storing values not operations. You need to put your methods in the public partition. Also methods are functions so they need braces to denote this fact.

since i dont have w/e library that is i cant run it through my compiler to check but i think it should probably look something like this.

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
#include <sfml/graphics.hpp>
using namespace std;
     
class game {

public:
	
void run(){
	while(mWindow.isOpen()){
		processEvents();
		update();
		render();
	}
}
	
void processEvents(){
    sf::Event event;
    while(mWindow.pollEvent(event)){
		if(event.type == sf::Event::Closed){
			mWindow.close();
		}
	}
}
	
void update(){
	mwindow.clear
	mWindow.draw(mPlayer);
	mwindow.display();
}
     
private:
	
void processEvents();
void update();
sf::RenderWindow mWindow;
sf::CircleShape mPlayer;
};
     
     
int main(){
    game0 game1; // i dont think this is your problem but its possable
    game1.run();
    return 0;
}
Last edited on
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
class game
{

public:
        void    run();
//...
};

void game::run()
{

}

I FIXED IT! and its all thanks to you, Market Anarchist!


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
#include <sfml/graphics.hpp>

using namespace std;


class game{    /**< This Class handles running the game, drawing the window
                        and proccessing the events */

public:

	void run(){
            while(mWindow.isOpen()){
                processEvents();
                update();
                }
            };
	void processEvents(){
        sf::Event event;

        while(mWindow.pollEvent(event)){
            if(event.type == sf::Event::Closed){
                mWindow.close();
                }
            }
        };
	void update(){
        mWindow.clear();

        mWindow.draw(mPlayer);
        mWindow.display();
        };

private:
           sf::RenderWindow mWindow;
           sf::CircleShape mPlayer;

};


int main(){
game game;
game.run();

return 0;
}
Topic archived. No new replies allowed.