SFML community forums
Help => Window => Topic started by: Xyro on November 02, 2009, 05:31:16 pm
-
I got some code
world.hpp
#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
#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 :
1>c:\users\quincy\documents\visual studio 2008\projects\space snapper\space snapper\world.cpp(4) : error C2758: 'World::Input' : must be initialized in constructor base/member initializer list
1> c:\users\quincy\documents\visual studio 2008\projects\space snapper\space snapper\world.hpp(13) : see declaration of 'World::Input'
I know this is something with initializers lists but I still don't know how to fix it.
-
You can initialize a reference only during its construction, so if it is a member you must do it in the initializer list:
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.