SFML community forums

Help => Window => Topic started by: Xyro on November 02, 2009, 05:31:16 pm

Title: Input
Post by: Xyro on November 02, 2009, 05:31:16 pm
I got some code



world.hpp
Code: [Select]

#ifndef WORLD
#define WORLD

#include <iostream>
#include <vector>
#include <SFML/Graphics.hpp>
#include "BaseEnt.hpp"
#include "Cockpit.hpp"

class World
{
private:
sf::Input& Input;
sf::Event Event;
sf::RenderWindow GameWindow;
public:
std::vector<BaseEnt*> Entities;
World();
void Draw();
void Think();
void CreateCockpit();
sf::RenderWindow &GetApp() {return GameWindow;}
};

#endif

world.cpp
Code: [Select]

#include "world.hpp"

World::World()
{
GameWindow.Create(sf::VideoMode(800,600,32),"Space Snapper",sf::Style::Close,sf::WindowSettings(8,24,2));
GameWindow.SetFramerateLimit(100);
Input = GameWindow.GetInput();
std::cout<<"World Created !" << std::endl;
}

Errors :

I know this is something with initializers lists but I still don't know how to fix it.
Title: Input
Post by: Laurent on November 02, 2009, 06:01:08 pm
You can initialize a reference only during its construction, so if it is a member you must do it in the initializer list:
Code: [Select]
World::World() :
GameWindow(sf::VideoMode(800,600,32),"Space Snapper", sf::Style::Close,sf::WindowSettings(8,24,2)),
Input(GameWindow.GetInput())
{
   std::cout<<"World Created !" << std::endl;
}

Make sure that GameWindow is declared before Input in your class definition, otherwise it won't work.