SFML community forums

Help => Window => Topic started by: treiguts on June 30, 2011, 12:41:00 pm

Title: Pointer to sf::Window
Post by: treiguts 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 )
Title: Re: Pointer to sf::Window
Post by: Nexus 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.
Title: Pointer to sf::Window
Post by: OniLinkPlus 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.