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

Author Topic: Pointer to sf::Window  (Read 3202 times)

0 Members and 1 Guest are viewing this topic.

treiguts

  • Newbie
  • *
  • Posts: 5
    • View Profile
Pointer to sf::Window
« on: June 30, 2011, 12:41:00 pm »
Code: [Select]

class a
{

sf::Window* m_Window; // class a member

a()
{
   m_Window = new sf::Window; // I make new window object
   m_Window.Create(...); // and creating window
}


error: request for member 'Create' in System*)this)->System::m_Window', which is of non-class type 'sf::Window*'|

Why can't I work with pointers? When I divide project in multiple classes, I can't pass Window to them and read pressed keys.
Code: [Select]
m_Window.GetInput().IsKeyDown( sf::Key::Left )

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Pointer to sf::Window
« Reply #1 on: June 30, 2011, 12:47:14 pm »
Quote from: "treiguts"
Why can't I work with pointers?
Why should you? Pointers are not necessary in your case. They just make the situation more complicated.
Code: [Select]
class a
{
    sf::Window m_Window;

    // Use the constructor initializer list
    a() : m_Window(sf::VideoMode(800, 600), "Title")
    {

    }
};

By the way, access to a member through a pointer requires the -> and not the . operator.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Pointer to sf::Window
« Reply #2 on: July 01, 2011, 02:21:16 am »
You should never use pointers unless it's absolutely necessary. 99% of the time, including this time, it isn't.
I use the latest build of SFML2

 

anything