I'm having trouble implementing an ImageManager into my program. I had success using this method with references:
//definition in Brick.h
ImageManager &imgr;
//constructor taking &imgr as a reference upon creation of object
Brick::Brick(ImageManager &im) : imgr(im){
//imgr is now a reference in my class, so it points to the same object that imgr in another class would point to
//this essentially makes one "static" instance of imgr, so all my graphic objects are dealing with the same instance of my ImageManager
imgr.doStuff()
}
This method of passing around my imgr used to work, until I started trying to remove obejcts from vectors. For instance, in my Level class I try to remove elements from a vector of Brick objects,
void Level::RemoveLine(int line){
//loop through every piece, loop through given piece's rects, if the rect falls on the removed line, then remove the piece
for(int i = 0; i < gamePieces_.size(); i++){
//crt new iterator per each gamepiece
auto write = gamePieces_[i].GetPieceRectangles().begin();
int j = 0;
for(auto read = write; read != gamePieces_[i].GetPieceRectangles().end(); read++){
if(gamePieces_[i].GetPieceRectangles()[j].GetActiveLine() != line){
if(read != write){
write = std::move(read);
}
write++;
}
}
gamePieces_[i].GetPieceRectangles().erase(write, gamePieces_[i].GetPieceRectangles().end());
}
}
but this doesn't work because ImageManager &imgr
declared in Brick.h
doesn't have a copy constructor, so it can't be copied in vectors when I try to .erase() the element. My goal is to implement one static ImageManager object to be used throughout all my classes. How would I go about doing this?