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

Author Topic: RenderWindow is not allowing me to access the function create.  (Read 4222 times)

0 Members and 3 Guests are viewing this topic.

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
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.
« Last Edit: May 07, 2016, 04:14:55 pm by BonBons »

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #1 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.
« Last Edit: May 07, 2016, 04:21:47 pm by Mr_Blame »

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderWindow is not allowing me to access the function create.
« Reply #2 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..

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #3 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?
« Last Edit: May 07, 2016, 04:25:24 pm by Mr_Blame »

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #4 on: May 07, 2016, 04:31:43 pm »
Rename your "create" to something another e.g. initMyWindow.

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderWindow is not allowing me to access the function create.
« Reply #5 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...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #6 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;
}
Laurent Gomila - SFML developer

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #7 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.
« Last Edit: May 07, 2016, 04:42:09 pm by Mr_Blame »

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderWindow is not allowing me to access the function create.
« Reply #8 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.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #9 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?
« Last Edit: May 07, 2016, 05:06:04 pm by Mr_Blame »

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderWindow is not allowing me to access the function create.
« Reply #10 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.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #11 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".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #12 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.
« Last Edit: May 08, 2016, 09:13:30 am by Laurent »
Laurent Gomila - SFML developer

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: RenderWindow is not allowing me to access the function create.
« Reply #13 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.

BonBons

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderWindow is not allowing me to access the function create.
« Reply #14 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!