SFML community forums

Help => General => Topic started by: Kamaitachi on July 27, 2012, 09:47:46 pm

Title: [SFML 1.6] Trying to access a class through a pointer
Post by: Kamaitachi on July 27, 2012, 09:47:46 pm
The situation is like this:

I have a class that handles the window and all the drawings, Window, and one to take care of the level, Level. Level takes as an argument in its constructor a Window object, and handles it with a pointer, using the arrow operator to access the public AddtoDraw() function, a function to allow adding elements to be drawn to a queue. The problems I get are the following:

||=== AI_Fighter, Debug ===|
C:\...\SFML-1.6\include\SFML\System\NonCopyable.hpp|57|error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private|
C:\...\SFML-1.6\include\SFML\Window\Window.hpp|56|error: within this context|
C:\...\SFML-1.6\include\SFML\System\NonCopyable.hpp|57|error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private|
C:\...\SFML-1.6\include\SFML\Window\Input.hpp|45|error: within this context|
C:\...\SFML-1.6\include\SFML\Window\Window.hpp|56|note: synthesized method 'sf::Input::Input(const sf::Input&)' first required here |
C:\...\SFML-1.6\include\SFML\Graphics\RenderWindow.hpp|46|note: synthesized method 'sf::Window::Window(const sf::Window&)' first required here |
C:\....\Window.hpp|8|note: synthesized method 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)' first required here |
C:\....\Main.cpp||In function 'int main()':|
C:\....\Main.cpp|12|note: synthesized method 'Window::Window(const Window&)' first required here |
C:\....\Main.cpp|12|error:   initializing argument 1 of 'Level::Level(Window)'|
||=== Build finished: 5 errors, 0 warnings ===|

I suppose, by the name NonCopyable,  that the sf::RenderWindow cannot be copied, and if I try to I will get an error. If such supposition is correct how I do what I described above (access a method of my rendering class, Window, so I can add elements to the queue, from an external class)?

Level.hpp
#ifndef Level_hpp
#define Level_hpp

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>

#include "Window.hpp"
#include "Level.hpp"

class Level
{
    Window *ResultScreen;
    sf::Image levelIMG;
    sf::Sprite levelSprite;
    std::vector<sf::Sprite> level;

    public:
    Level( Window );
    void PassDrawLevel();
};

#endif

Level.cpp
#include "Level.hpp"
#include "Window.hpp"

Level::Level( Window app )
{
    *ResultScreen = app;

    if( !levelIMG.LoadFromFile("TileSet.png") )
    {
        std::cout << "Problem opening file 'TileSet.png'";
    }

    levelIMG.SetSmooth(false);

    levelSprite.SetImage( levelIMG );
};

void Level::PassDrawLevel ()
{
    ResultScreen->AddtoDraw( level );
}
Title: Re: [SFML 1.6] Trying to access a class through a pointer
Post by: Laurent on July 28, 2012, 09:37:40 am
Either
Level::Level( Window* app )
{
    ResultScreen = app;
or
Level::Level( Window& app )
{
    ResultScreen = &app;
Title: Re: [SFML 1.6] Trying to access a class through a pointer
Post by: Kamaitachi on July 28, 2012, 10:05:48 am
Thank you!