-
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.
-
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.
-
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..
-
Which error message you get? Still the same?
EDIT:
Are you supposed to initialize sf::VideoMode that way?
-
Rename your "create" to something another e.g. initMyWindow.
-
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...
-
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;
}
-
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.
-
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.
-
Look at RenderWindow.h maybe somehow the sf::RenderWindow::create got renamed.
EDIT:
Which SFML version you have?
-
Look at RenderWindow.h maybe somehow the sf::RenderWindow::create got renamed.
Not sure how to do that, sorry.
-
Right click on sf::RenderWindow and press "go to defenition" and you will arrive at "RenderWindow.hpp".
-
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.
-
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.
-
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!