SFML community forums

Help => General => Topic started by: BonBons on May 07, 2016, 04:02:12 pm

Title: RenderWindow is not allowing me to access the function create.
Post by: BonBons on May 07, 2016, 04:02:12 pm
Hello. I am just wondering why I cant access the create function of the RenderWindow class. I can access the Display and Clear functions so I am rather confused as to why this is.

#ifndef WINDOW_H
#define WINDOW_H

#include <string>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
class Window
{
public:
        Window();
        Window(std::string& title, sf::Vector2u& windowSize);
        ~Window();

private:
        std::string m_title;
        sf::Vector2u m_windowSize;
        sf::RenderWindow m_window;
        bool m_fullScreen;
        bool m_isDone;

        void setup(const std::string& title, sf::Vector2u windowSize);
        void create();
};

#include "Window.h"


Window::Window()
{
        setup("My Window", sf::Vector2u(640, 480));
}

Window::Window(std::string & title, sf::Vector2u & windowSize)
{
        setup(title, windowSize);
}


Window::~Window()
{
}

void Window::setup(const std::string & title, sf::Vector2u windowSize)
{
        m_title = title;
        m_windowSize = windowSize;
        m_fullScreen = false;
        m_isDone = false;
        create();
}

void Window::create()
{
        auto style = (m_fullScreen ? sf::Style::Fullscreen : sf::Style::Default);
        m_window.create() //sf::RenderWindow has no member "create"
}

#endif // !WINDOW_H


 

Thank you in advance.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Mr_Blame on May 07, 2016, 04:17:44 pm
Sf::RenderWindow::create needs some arguments, it cannot be called with no arguments(see API documentation). So error message, that you get, is correct there is no such sf::RenderWindow::create overload that accepts no arguments.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: BonBons on May 07, 2016, 04:22:35 pm
m_window.create({ m_windowSize.x, m_windowSize.y, 32 }, m_windowTitle, style);

Still not registering as a member of the class RenderWindow. Quite confused now..
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Mr_Blame on May 07, 2016, 04:23:26 pm
Which error message you get? Still the same?

EDIT:
Are you supposed to initialize sf::VideoMode that way?
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Mr_Blame on May 07, 2016, 04:31:43 pm
Rename your "create" to something another e.g. initMyWindow.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: BonBons on May 07, 2016, 04:34:29 pm
Error   C2039   'create': is not a member of 'sf::RenderWindow'
This is the error after I have renamed the function name. This is so strange...
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Laurent on May 07, 2016, 04:36:19 pm
Can you post a complete and minimal code that reproduces the error ?

Hint: this could be a good starting point
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow w;
    w.create({640, 480, 32}, "test");
    return 0;
}
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Mr_Blame on May 07, 2016, 04:40:08 pm
Why do you include "Window.h" in "Window.h" this already must cause compilation error.
#ifndef WINDOW_H
#define WINDOW_H

#include <string>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
class Window
{
public:
    Window();
    Window(std::string& title, sf::Vector2u& windowSize);
    ~Window();

private:
    std::string m_title;
    sf::Vector2u m_windowSize;
    sf::RenderWindow m_window;
    bool m_fullScreen;
    bool m_isDone;

    void setup(const std::string& title, sf::Vector2u windowSize);
    void create();
};

#include "Window.h" //<- why


Window::Window()
{
    setup("My Window", sf::Vector2u(640, 480));
}

Window::Window(std::string & title, sf::Vector2u & windowSize)
{
    setup(title, windowSize);
}


Window::~Window()
{
}

void Window::setup(const std::string & title, sf::Vector2u windowSize)
{
    m_title = title;
    m_windowSize = windowSize;
    m_fullScreen = false;
    m_isDone = false;
    create();
}

void Window::create()
{
    auto style = (m_fullScreen ? sf::Style::Fullscreen : sf::Style::Default);
    m_window.create() //sf::RenderWindow has no member "create"
}

#endif // !WINDOW_H

 
Because as long as I see this, it makes me think, that function definitions and function declarations are in the same file.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: BonBons on May 07, 2016, 04:40:54 pm
Can you post a complete and minimal code that reproduces the error ?

Hint: this could be a good starting point
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow w;
    w.create({640, 480, 32}, "test");
    return 0;
}

I have the same issue as before. This is very odd.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Mr_Blame on May 07, 2016, 04:45:19 pm
Look at RenderWindow.h maybe somehow the sf::RenderWindow::create got renamed.

EDIT:
Which SFML version you have?
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: BonBons on May 07, 2016, 05:01:37 pm
Look at RenderWindow.h maybe somehow the sf::RenderWindow::create got renamed.

Not sure how to do that, sorry.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Mr_Blame on May 07, 2016, 05:04:05 pm
Right click on sf::RenderWindow and press "go to defenition" and you will arrive at "RenderWindow.hpp".
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Laurent on May 07, 2016, 06:14:28 pm
Mr_Blame, this is cool that you want to help, but could you please stop replying random ideas :P

If you think that the create function was renamed it takes only 30 seconds to check that in the official documentation (and no it wasn't renamed). There's also no reason why his own create function could create such a problem (his class doesn't inherit from sf::RenderWindow, it's just a member). And yes, in C++11 we can initialize structures this way.

BonBons, if this minimal example triggers the same error, then there's something very wrong in your environment. The code I posted is perfectly valid.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: Mr_Blame on May 07, 2016, 08:58:27 pm
And yes, in C++11 we can initialize structures this way.

My bad :)

Didn't try this feature so long that I began to think, that this is a C only style.
Title: Re: RenderWindow is not allowing me to access the function create.
Post by: BonBons on May 08, 2016, 05:28:10 pm
Ah! Yeah it's fixed now. Not sure what happened to that project but it has been to the far corners of my computer and had to start another. Thanks all!