I'm getting a linking error(I think) when trying to compile my program.
This is my Game.h file:
#ifndef GAME_H
#define GAME_H
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
class Game {
private:
sf::RenderWindow *window;
public:
Game();
~Game();
void start();
};
#endif
And this is my Game.cpp file:
#include "Game.h"
Game::Game() {
this->window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Pong", !sf::Style::Resize | sf::Style::Close);
}
Game::~Game() {
}
void Game::start() {
}
This is the build script I am using, the dll files are in the same directory as the code files.
g++ -o Pong.exe Main.cpp Game.h Game.cpp -lsfml-system -lsfml-graphics -lsfml-audio
Any way to fix this?
You need to link sfml-window, and consider the correct link order. Please read the tutorial...
By the way, what should the negation operator in !sf::Style::Resize mean? And why do you need manual memory management and a destructor? Just define your class as follows:
class Game
{
private:
sf::RenderWindow window; // No pointer
public:
Game();
void start();
};
Game::Game()
: window(sf::VideoMode(800, 600, 32), "Pong", sf::Style::Resize | sf::Style::Close)
{
// Because of the constructor initializer list, the body remains empty
}
void Game::start()
{
}
You need to link sfml-window, and consider the correct link order. Please read the tutorial...
By the way, what should the negation operator in !sf::Style::Resize mean? And why do you need manual memory management and a destructor? Just define your class as follows:
class Game
{
private:
sf::RenderWindow window; // No pointer
public:
Game();
void start();
};
Game::Game()
: window(sf::VideoMode(800, 600, 32), "Pong", sf::Style::Resize | sf::Style::Close)
{
// Because of the constructor initializer list, the body remains empty
}
void Game::start()
{
}
Thank you for the quick response :) All works fine now. I'm sorry for being a noob at this, I don't fully understand the concept of pointers and memory management(I come from a Java background)