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

Author Topic: Problem with sf::NonCopyable  (Read 7550 times)

0 Members and 1 Guest are viewing this topic.

blargly

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problem with sf::NonCopyable
« on: February 23, 2010, 02:05:59 pm »
I'm currently trying to put together an object manager class for game which has an update method which draws each of the sprites in the game. In order to do this, I needed an sf::RenderWindow object to be passed to my object manager and then draw each sprite.
However, when I pass my window I get the following error:

error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'

I made sure that only references were being passed, but the same error still occurs, which I thought to be odd considering a reference isn't an actual copy.

Code: [Select]
int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Pong", sf::Style::Fullscreen);

ObjManager OMan(App);


Code: [Select]
ObjManager::ObjManager(sf::RenderWindow& App)
{

}


Sorry if I've made some rookie errors here, I'm still a relatively new programmer, and I've just started getting into using libraries like SFML in order to implement graphics into my games.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Problem with sf::NonCopyable
« Reply #1 on: February 23, 2010, 02:08:28 pm »
I don't see an error in the code you've posted. Could you show us the class definition of ObjManager?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

blargly

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problem with sf::NonCopyable
« Reply #2 on: February 23, 2010, 02:12:46 pm »
Code: [Select]
class ObjManager
{
public:
ObjManager(sf::RenderWindow& App);
~ObjManager();

sf::RenderWindow LocWindow;

void AddObject();
void Update();

std::list<Player>m_PlayerList;

};


Just to note Player is a class which inherits from sf::Sprite but the same issue occurs even if everything bar the constructor is commented.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Problem with sf::NonCopyable
« Reply #3 on: February 23, 2010, 02:19:37 pm »
Are you sure that ObjManager needs an own, independent instance of sf::RenderWindow? Or did you just forget the reference (&)?
Code: [Select]
class ObjManager
{
                ...
sf::RenderWindow LocWindow;
                ...
};

I guess you have got something like the following in your code, which isn't valid since sf::RenderWindow is noncopyable.
Code: [Select]
LocWindow = App
After declaring LocWindow as reference, use the initializer list in your constructor:
Code: [Select]
ObjManager::ObjManager(sf::RenderWindow& App)
: LocWindow(App)
{
}
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

blargly

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problem with sf::NonCopyable
« Reply #4 on: February 23, 2010, 02:32:16 pm »
Code: [Select]
LocWindow = App

Yeah that's right, I was using the above, and ObjManager was using its own independent instance of sf::RenderWindow.
Ok, just made the changes and the problem is solved, many thanks!

 

anything