SFML community forums
Help => Graphics => Topic started by: Xyro on June 13, 2011, 04:29:37 pm
-
So I am switching from C# to c++, I managed to compile sfml 2.0 and create a renderwindow. Then I wanted to wrap it inside a world class and for some reason it keeps spitting out these errors :
c:\users\quincy\sfml-2.0\laurentgomila-sfml-79d5217\include\sfml\window\window.hpp(500): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\users\quincy\sfml-2.0\laurentgomila-sfml-79d5217\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\users\quincy\sfml-2.0\laurentgomila-sfml-79d5217\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'
1>c:\users\quincy\sfml-2.0\laurentgomila-sfml-79d5217\include\sfml\graphics\rendertarget.hpp(304): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\users\quincy\sfml-2.0\laurentgomila-sfml-79d5217\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\users\quincy\sfml-2.0\laurentgomila-sfml-79d5217\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::RenderTarget::RenderTarget(const sf::RenderTarget &)'
Now I have looked at other problems and I am not or at least I think not passing the renderwindow by value anywhere.
My code :
main.cpp
//Some includes
int main()
{
World world = World(sf::VideoMode(1280, 1024, 32), "Sfml is finaly set up properly !");
while(world.GetWindow().IsOpened())
{
double frameTime = world.GetWindow().GetFrameTime() / 1000;
std::cout << "Frametime in sec : " << frameTime;
world.Think(frameTime);
world.Draw(frameTime);
}
return EXIT_SUCCESS;
}
world.cpp / world.h
//.h
#pragma once
#include <SFML\Graphics.hpp>
#include <string>
class World
{
private:
sf::RenderWindow RenderWindow;
public:
sf::RenderWindow &GetWindow() {return RenderWindow;}
void Think(double);
void Draw(double);
World(sf::VideoMode, std::string);
~World();
};
//.cpp
#include "World.h"
World::World(sf::VideoMode videoMode, std::string title)
{
RenderWindow.Create(videoMode, title);
}
World::~World()
{
}
void World::Draw(double frameTime)
{
RenderWindow.Clear();
//Do drawing in between
RenderWindow.Display();
}
void World::Think(double frameTime)
{
sf::Event event;
while (RenderWindow.PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
RenderWindow.Close();
}
}
Also a small c++ question, I thought this :
sf::RenderWindow &GetWindow() {return RenderWindow;}
Would give a reference of the window and that I had to access its members with -> but it seems I have to do
while(world.GetWindow().IsOpened())
why is that ?
-
Also a small c++ question, I thought this :
Code:
sf::RenderWindow &GetWindow() {return RenderWindow;}
Would give a reference of the window and that I had to access its members with -> but it seems I have to do
In C++, a reference doesn't use the pointer to member operator '->', just the normal member operator '.'. That is for pointers. One of the advantages of references over pointers is the cleaner notation which results from this.
EDIT: I see you are using Quincy. Are you a fellow reader of Wiley's "Teach Yourself C++"?
-
No I am just using http://www.cplusplus.com/doc/tutorial/ to teach myself.
Also what does my name have to do with me reading a book about c++ haha ?
also thanks for clearing that up
-
Oh I see lol. Quincy is the name of an IDE which the author of that book wrote. I glanced at your path and assumed it was in Program Files, not Users :P
-
World world = World(sf::VideoMode(1280, 1024, 32), "Sfml is finaly set up properly !");
Here you're constructing your "world" variable by copying a temporary World instance. But sf::RenderWindow is not copyable, so your World class is not copyable.
Do this instead, to avoid the copy:
World world(sf::VideoMode(1280, 1024, 32), "Sfml is finaly set up properly !");
-
Wow, thanks I still need to get used to c++, I have already caught myself trying to type class name = new class haha.
-
@OP, On an unrelated note, if you like C++ and C# then (once you're happy with C++) you should try D. I have finally got round to trying it and it's quite nice - since it's quite easy to migrate between such similar langauges there's no harm in trying it, right? ;)