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

Author Topic: Making a game engine, question about managers and SFML...  (Read 3866 times)

0 Members and 1 Guest are viewing this topic.

epicasian

  • Newbie
  • *
  • Posts: 14
    • View Profile
Making a game engine, question about managers and SFML...
« 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:
Code: [Select]
sf::Input& MainInput = MainWindow.GetInput();, MSVC++ says this:
Code: [Select]
'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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Making a game engine, question about managers and SFML...
« Reply #1 on: July 25, 2010, 07:21:34 pm »
You probably didn't include the header which defines MainWindow.
Laurent Gomila - SFML developer

epicasian

  • Newbie
  • *
  • Posts: 14
    • View Profile
Making a game engine, question about managers and SFML...
« Reply #2 on: July 25, 2010, 07:24:43 pm »
I'm including it like so.

Code: [Select]

#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

Code: [Select]


#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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Making a game engine, question about managers and SFML...
« Reply #3 on: July 25, 2010, 07:27:53 pm »
Code: [Select]
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.
Laurent Gomila - SFML developer

epicasian

  • Newbie
  • *
  • Posts: 14
    • View Profile
Making a game engine, question about managers and SFML...
« Reply #4 on: July 25, 2010, 07:33:31 pm »
But when I move over that to the implementation file, I get this error:

Code: [Select]
inputmanager.cpp(6) : error C2758: 'tnt::InputManager::MainInput' : must be initialized in constructor base/member initializer list

Thanks again.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Making a game engine, question about managers and SFML...
« Reply #5 on: July 25, 2010, 08:09:33 pm »
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.
Code: [Select]
InputManager::InputManager() : MainInput(MainWindow.GetInput())
{
}
Laurent Gomila - SFML developer

epicasian

  • Newbie
  • *
  • Posts: 14
    • View Profile
Making a game engine, question about managers and SFML...
« Reply #6 on: July 25, 2010, 08:30:51 pm »
VC++ is still saying:

Code: [Select]

inputmanager.cpp(6) : error C2065: 'MainWindow' : undeclared identifier

inputmanager.cpp(6) : error C2228: left of '.GetInput' must have class/struct/union

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Making a game engine, question about managers and SFML...
« Reply #7 on: July 25, 2010, 08:34:37 pm »
What is MainWindow? If it's the member of WindowManager, you obviously need an instance of this class to get its MainWindow.
Laurent Gomila - SFML developer