SFML community forums
Help => Window => Topic started by: epicasian on July 25, 2010, 07:06:12 pm
-
Hello, I'm new to SFML and I have to say I love it. My problem is that I'm trying to make a game engine, and I'm separating the WindowManager and the InputManager in different classes. I have the one instance of sf::RenderWindow named MainWindow. Then, I'm making a WindowManager friends with InputManager to get the MainWindow, because it is private. But when I try to do this:
sf::Input& MainInput = MainWindow.GetInput();
, MSVC++ says this: 'MainWindow' : undeclared identifier, left of '.GetInput' must have class/struct/union,
and a few other errors.
All help is greatly appreciated,
~Asian
PS. Sorry if I didn't include enough info, please tell me and I'll try to tell you more. Thanks again!
-
You probably didn't include the header which defines MainWindow.
-
I'm including it like so.
#ifndef INPUTMANAGER_H_
#define INPUTMANAGER_H_
#include "WindowManager.h"
namespace tnt
{
class InputManager
{
private:
sf::Input& MainInput = MainWindow.GetInput(); //error here...
public:
InputManager();
bool IsKeyDown(sf::Key::Code KeyName);
};
}
#endif
#ifndef WINDOWMANAGER_H_
#define WINDOWMANAGER_H_
#include <SFML/Graphics.hpp>
#include <string>
namespace tnt
{
class WindowManager
{
private:
sf::RenderWindow MainWindow;
int WindowWidth;
int WindowHeight;
int WindowBPP;
std::string WindowTitle;
public:
WindowManager();
void CloseWindow();
void DisplayWindow();
void ToggleFullscreen();
void ChangeResolution(int width, int height);
friend class InputManager;
};
}
#endif
Thanks again.
-
sf::Input& MainInput = MainWindow.GetInput(); //error here...
You can't write such code in the class definition, it must contain only declarations. Do this in your constructor.
-
But when I move over that to the implementation file, I get this error:
inputmanager.cpp(6) : error C2758: 'tnt::InputManager::MainInput' : must be initialized in constructor base/member initializer list
Thanks again.
-
A reference must be bound to a variable at the time it is created. So, to initialize a reference member, you have to use the initialization list like the compiler says.
InputManager::InputManager() : MainInput(MainWindow.GetInput())
{
}
-
VC++ is still saying:
inputmanager.cpp(6) : error C2065: 'MainWindow' : undeclared identifier
inputmanager.cpp(6) : error C2228: left of '.GetInput' must have class/struct/union
-
What is MainWindow? If it's the member of WindowManager, you obviously need an instance of this class to get its MainWindow.