SFML community forums
Help => General => Topic started by: fatum on August 21, 2011, 06:46:37 am
-
Inside of my player.h file:
class Player
{
private:
sf::RenderWindow App;
...
//
public:
Player(sf::RenderWindow App);
...
//
};
Inside of my player.cpp file:
Player::Player(sf::RenderWindow getApp)
{
App = getApp;
...
}
Inside of my main.cpp file:
int main(int argc, char** argv)
{
sf::RenderWindow App(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP), "Hey There!");
Player player(App);
...
}
However, a large amount of issues are reported:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Window.hpp:40:0,
from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:32,
from player.h:1,
from player.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp: In member function 'sf::Window& sf::Window::operator=(const sf::Window&)'
:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp:79:18: error: 'sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCo
pyable&)' is private
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Window/Window.hpp
:57:1: error: within this context
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:39:0,
from player.h:1,
from player.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp: In member function 'sf::RenderWindow& sf::RenderWindow::operator=(cons
t sf::RenderWindow&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp:44:1: note: synthesized method 'sf::Window& sf::Window::operator=(const
sf::Window&)' first required here
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics/RenderTexture.hpp:32:0,
from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:38,
from player.h:1,
from player.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp: In member function 'sf::RenderTarget& sf::RenderTarget::operator=(const s
f::RenderTarget&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp:79:18: error: 'sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCo
pyable&)' is private
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderTa
rget.hpp:48:1: error: within this context
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:37:0,
from player.h:1,
from player.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp: In member function 'sf::Renderer& sf::Renderer::operator=(const sf::Rende
rer&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp:79:18: error: 'sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCo
pyable&)' is private
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/Renderer
.hpp:49:1: error: within this context
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/Renderer
.hpp:49:1: error: non-static reference member 'sf::RenderTarget& sf::Renderer::m
yTarget', can't use default assignment operator
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics/RenderTexture.hpp:32:0,
from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:38,
from player.h:1,
from player.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderTa
rget.hpp: In member function 'sf::RenderTarget& sf::RenderTarget::operator=(cons
t sf::RenderTarget&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderTa
rget.hpp:48:1: note: synthesized method 'sf::Renderer& sf::Renderer::operator=(c
onst sf::Renderer&)' first required here
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:39:0,
from player.h:1,
from player.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp: In member function 'sf::RenderWindow& sf::RenderWindow::operator=(cons
t sf::RenderWindow&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp:44:1: note: synthesized method 'sf::RenderTarget& sf::RenderTarget::ope
rator=(const sf::RenderTarget&)' first required here
player.cpp: In constructor 'Player::Player(sf::RenderWindow)':
player.cpp:5:8: note: synthesized method 'sf::RenderWindow& sf::RenderWindow::op
erator=(const sf::RenderWindow&)' first required here
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Window.hpp:40:0,
from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:32,
from main.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp: In copy constructor 'sf::Window::Window(const sf::Window&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp:67:5: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is pri
vate
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Window/Window.hpp
:57:1: error: within this context
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:39:0,
from main.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp: In copy constructor 'sf::RenderWindow::RenderWindow(const sf::RenderWi
ndow&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp:44:1: note: synthesized method 'sf::Window::Window(const sf::Window&)'
first required here
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics/RenderTexture.hpp:32:0,
from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:38,
from main.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp: In copy constructor 'sf::RenderTarget::RenderTarget(const sf::RenderTarge
t&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp:67:5: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is pri
vate
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderTa
rget.hpp:48:1: error: within this context
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:37:0,
from main.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp: In copy constructor 'sf::Renderer::Renderer(const sf::Renderer&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/System/NonCopyabl
e.hpp:67:5: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is pri
vate
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/Renderer
.hpp:49:1: error: within this context
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics/RenderTexture.hpp:32:0,
from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:38,
from main.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderTa
rget.hpp: In copy constructor 'sf::RenderTarget::RenderTarget(const sf::RenderTa
rget&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderTa
rget.hpp:48:1: note: synthesized method 'sf::Renderer::Renderer(const sf::Render
er&)' first required here
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
SFML/Graphics.hpp:39:0,
from main.cpp:1:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp: In copy constructor 'sf::RenderWindow::RenderWindow(const sf::RenderWi
ndow&)':
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/SFML/Graphics/RenderWi
ndow.hpp:44:1: note: synthesized method 'sf::RenderTarget::RenderTarget(const sf
::RenderTarget&)' first required here
main.cpp: In function 'int main(int, char**)':
main.cpp:26:19: note: synthesized method 'sf::RenderWindow::RenderWindow(const s
f::RenderWindow&)' first required here
main.cpp:26:19: error: initializing argument 1 of 'Player::Player(sf::RenderWi
ndow)'
What could the issue be? Thanks for any assistance!
Also, the ... symbolizes that I took out pieces of irrelevant code.
-
You can't copy windows, which is what you're doing. Pass a reference to the window instead.
-
You can't copy windows, which is what you're doing. Pass a reference to the window instead.
Thanks for the reply! Here's what I'm currently trying:
player.h file
class Player
{
private:
sf::RenderWindow App;
..
//
public:
Player(sf::RenderWindow &getApp);
...
//
};
player.cpp
Player::Player(sf::RenderWindow &getApp)
{
App = getApp;
...
}
main.cpp
Player player(&App);
However, it appears that essentially the same message from the original post is returned. What could the issue be?
-
You can't copy windows, which is what you're doing. Pass a reference to the window instead.
What could the issue be?
The issue is right here
player.h file
class Player
{
private:
sf::RenderWindow App;
..
//
public:
Player(sf::RenderWindow &getApp);
...
//
};
Change the sf::RenderWindow App to sf::RenderWindow &App, and initialize it with an initialization list.
-
Thanks for the help again! Could you please elaborate on what you mean by initialization lists? I've found a few articles, and it looked like they were pointing towards something like this:
player.h
public:
Player(sf::RenderWindow &getApp);
Player();
player.cpp
Player::Player(sf::RenderWindow &getApp) : App(&App)
I'm sure that what I'm currently trying to do looks pretty ridiculous, it certainly doesn't feel right.
-
Initializer lists are a language feature to initialize member variables in the constructor. You should always prefer them over assignments in the constructor body. Sometimes they are unavoidable (for references, constants, not default-constructible objects).
Do you have a good C++ book, such as the C++ primer, Accelerated C++ or Thinking in C++? If not, you should really read one, it is certainly worth the time and money.
-
I was able to eliminate all of the errors. Currently I'm trying with:
player.h
public:
void update(sf::RenderWindow &App);
player.cpp
Player::Player(float getX, float getY, sf::Texture getImg)
{
sf::Sprite self(getImg);
...
}
void Player::update(sf::RenderWindow &App)
{
App.Draw(self);
}
main.cpp
App.Clear();
player.update(App);
App.Display();
The "App.Draw(self);" is causing the issue. Without it, the code compiles without any errors. Here are the errors returned:
player.cpp: In member function 'void Player::update(sf::RenderWindow&)':
player.cpp:37:15: error: no matching function for call to 'sf::RenderWindow::Draw(sf::Texture&)'
Also, I do have a really interesting C++ book that I like to read through sometimes. Do you have any recommendations?
-
Your error happens to me sometimes when I'm typing code on auto-mode.
in player.cpp:
sf::Sprite self(getImg);
This declares a local sprite, named self.
Now I am guessing you have a member of your player class called self declared somewhere (Why else would you call App.Draw(self)?). The compiler error hints that the type of this class is a sf::Texture too (while it's probably meant to be a sf::Sprite?).
The code is too incomplete to come up with a solution. But just remember that to call a non-default constructor of a member variable you have to call it in the initialization list.
You can also just use the SetTexture function that is provided.
-
Your error happens to me sometimes when I'm typing (while it's probably meant to be a sf::Sprite?).
Wow, that was it. lol I can't believe I overlooked that I gave self the wrong type in my player.h file. There currently are not any errors, however nothing is displayed. Here's my Player's constructor:
Player::Player(float getX, float getY, sf::Texture getImg)
{
sf::Sprite self(getImg);
x = getX;
y = getY;
self.SetPosition(getX, getY);
}
(I also tried using .SetTexture(); as well)
main.cpp
sf::Texture img_player;
if (!img_player.LoadFromFile("res/img/char/player.png"))
{
return EXIT_FAILURE;
}
Player player(20, 20, img_player);
...
while (App.IsOpened())
{
App.Clear();
player.update(App);
App.Display();
}
Also, if it's helpful:
player.h
#include "SFML/Graphics.hpp"
#include <iostream>
class Player
{
private:
float x, y, xs, ys, speed, fric;
bool right, left;
sf::Sprite self;
//
public:
Player(float getX, float getY, sf::Texture getImg);
void input(sf::Event event);
void update(sf::RenderWindow &App);
//
};
If I replaced it with this bit:
main.cpp
sf::Texture img_player;
if (!img_player.LoadFromFile("res/img/char/player.png"))
{
return EXIT_FAILURE;
}
sf::Sprite spr_player(img_player);
spr_player.SetPosition(10.0f, 10.0f);
while (App.IsOpened())
{
App.Clear();
//player.update(App);
App.Draw(spr_player);
App.Display();
}
The sprite is displayed on the screen. What could I be doing wrong?
-
jkalmeij already pointed the error.
You defined the local 'sf::Sprite self' inside the constructor and initialized it instead of the member variable 'self'.
-
If anyone is looking for a solution to a similar problem, here's what I implemented:
player.h
public:
void update(sf::Sprite &spr_player);
...
//
player.cpp
void Player::update(sf::Sprite &spr_player)
{
main.cpp
bool setup()
{
if (!img_player.LoadFromFile("res/img/char/player.png"))
{
return false;
}
spr_player.SetTexture(img_player);
return true;
}
int main(int argc, char** argv)
{
...
if (setup() == false)
{
return EXIT_FAILURE;
}
Player player(20, 20);
while (App.IsOpened())
{
..
App.Clear();
App.Draw(spr_player);
player.update(spr_player);
App.Display();
}
return EXIT_SUCCESS;
}
I'm also probably going to create an array that holds all of the sprites that need displaying, and call App.Draw(spriteBatch[index]); in a for loop.
-
Thank you for your share, I really liked your article, I think you said something very meaningful. I will often come to your published article, hope that something is to see something different each time
Cheap Polo Shirts (http://www.poloshirtsonsales.com)
Women's RL Polo Shirts (http://www.poloshirtsonsales.com/womens-rl-polo-shirts-c-9.html)
slimming tea (http://www.slimmingshops.com/)