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

Author Topic: Problem with creating a renderwindow  (Read 4684 times)

0 Members and 1 Guest are viewing this topic.

Xyro

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Problem with creating a renderwindow
« 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 :

Code: [Select]

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
Code: [Select]

//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

Code: [Select]

//.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 :
Code: [Select]

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

Code: [Select]

while(world.GetWindow().IsOpened())


why is that ?

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
Problem with creating a renderwindow
« Reply #1 on: June 13, 2011, 04:48:38 pm »
Quote
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++"?

Xyro

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Problem with creating a renderwindow
« Reply #2 on: June 13, 2011, 04:52:27 pm »
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

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
Problem with creating a renderwindow
« Reply #3 on: June 13, 2011, 04:56:27 pm »
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with creating a renderwindow
« Reply #4 on: June 13, 2011, 05:51:26 pm »
Quote
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:
Code: [Select]
World world(sf::VideoMode(1280, 1024, 32), "Sfml is finaly set up properly !");
Laurent Gomila - SFML developer

Xyro

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Problem with creating a renderwindow
« Reply #5 on: June 13, 2011, 06:56:20 pm »
Wow, thanks I still need to get used to c++, I have already caught myself trying to type class name = new class haha.

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
Problem with creating a renderwindow
« Reply #6 on: June 13, 2011, 07:01:44 pm »
@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? ;)