1
General / Getting an object from another file
« on: April 12, 2011, 03:48:19 am »
I am trying to make a window class and an input handling class. I created an instance of sf::RenderWindow in the Window.cpp. I need to use this object in my Input.cpp file. What would be the best way of doing this?
Window.cpp
Input.cpp
Window.cpp
Code: [Select]
#include "Window.hpp"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
namespace
{
sf::RenderWindow window; //This is the object I need
sf::Event Event;
}
Window::Window(int sizeX, int sizeY)
{
width = sizeX;
height = sizeY;
scaleX = (scaleX * (width / 800));
scaleY = (scaleY * (height / 600));
}
Input.cpp
Code: [Select]
#include "Input.hpp"
#include "Window.hpp"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
namespace
{
const sf::Input &input = window.GetInput(); //window not declared in this scope
}
Input::Input()
{
while (input.IsKeyDown(sf::Key::Left)){
Input::LeftKeyDown = true;}
Input::LeftKeyDown = false;