> After doing that, imgr no longer behaves like a reference, like in this code here
> void Brick::SetSizePosTextColor(ImageManager &im, sf::Vector2i size, int posx, int > posy, sf::Color color){
> //...
> brick.setTexture(imgr.tetrominoTexture);
> //...
> }
> So in Brick, I need the imgr to behave like a reference would. How does it do that when it is wrapped?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class Brick{
public:
Brick(ImageManager &im) : imgr_wrapper (im) {}
// ...
private:
std::reference_wrapper<ImageManager> imgr_wrapper ; // wrapped
ImageManager& imgr() { return imgr_wrapper ; }
const ImageManager& imgr() const { return imgr_wrapper ; }
// ...
};
|
And then
1 2 3 4 5
|
void Brick::SetSizePosTextColor(ImageManager &im, sf::Vector2i size, int posx, int posy, sf::Color color){
//...
brick.setTexture( imgr().tetrominoTexture);
//...
}
|
> added std::ref(imgr) to the constructor
No. Just remove it.
> Adding a copy constructor does not help.
Remove that too; use the implicitly declared copy constructor.
> I'd suggest to use a list. vector is rather slow when it comes to erase an arbitrary element.
Erasing with the remove-erase idiom on
std::vector<> would be measurably faster than on
std::list<>
https://en.wikipedia.org/wiki/Erase-remove_idiom