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