Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Input  (Read 1839 times)

0 Members and 1 Guest are viewing this topic.

Xyro

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Input
« 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 :
    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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32502
    • View Profile
    • SFML's website
    • Email
Input
« Reply #1 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.
Laurent Gomila - SFML developer

 

anything