Reputation: 43
I'm trying to create an object where the SFML RenderWindow object is passed over as a parameter, but it isn't simply working, it complains all the time about pointer and that I'm using them in the wrong way.
Here you have my .h file:
#include <iostream>
#include <SFML\System.hpp>
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>
using namespace sf;
class Shot
{
private:
RenderWindow &mainWindow;
public:
Shot(RenderWindow &window);
void add(float x, float y, float velocity);
};
and here my .cpp
#include "Shot.h"
Shot::Shot(RenderWindow &window) : mainWindow(&window)
{
mainWindow -> window;
}
void Shot::add(float x, float y, float velocity)
{
CircleShape shape(10);
shape.setPosition(Vector2f(x, y));
shape.setFillColor(Color::Yellow);
mainWindow.draw(shape);
}
Errors:
Error 1 error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'
Error 2 error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'
i honestly have no clue what's the problem by now an I've probably done it all wrong, but any help would really be appreciated! :)
Best Regards
FreeSirenety
Upvotes: 0
Views: 1794
Reputation:
In your .cpp file, you do:
Shot::Shot(RenderWindow &window) : mainWindow(&window)
{
mainWindow -> window;
}
but window
is a reference, so you simply can do:
Shot::Shot(RenderWindow &window) : mainWindow(window)
{}
Also, I wouldn't use using namespace sf;
, it can make the code confusing after awhile.
Upvotes: 1