So I have an ImageManager class, Board class, and Box class. In Board.h I can declare ImageManager imgr; and in Board's constructor I can use imgr and its functions and such. However, in Box.h when I try and declare ImageManager imgr; I get the error "cannot access member declared in class ImageManager". Both declarations are under private, and exactly the same, but one doesn't work. Can anybody help? Also, is there a way to only have one instance of ImageManager?
You have not provided enough information for us to know what the problem is - please provide a minimal example that has the same error, or at the very least paste your code.
As for only having one ImageManager, you can have Board and Box take a reference to an ImageManager in their constructors and then you can construct them both from the same ImageManager. Don't use a singleton though; as a community we've agreed it's more of an anti-pattern.
Board::Board(){
imgr.AddResourceDirectory("images/");
//error checking, images/ is indeed in the vector
//std::cout << imgr.GetResourceDirectory()[0];
gameBoard.setTexture(imgr.GetImage("t3board.png"));
}
I'll bet you anything it's trying to implicitly access the copy constructor of ImageManager when you try to copy a Box into the vector. Using a reference would definitely solve the problem.
Alright thanks, I think I'll try using just one ImageManager with references like you said. But where would the one instance of ImageManager be? In my game engine class? In the ImageManager class?
Right, sorry the wording eluded my grasp. Anyways, having done that, how do I access this ImageManager from my other classes? The details of this new problem are in my post here: http://stackoverflow.com/questions/25676303/how-do-i-implement-my-imagemanager?
But essentially, I just want to know how to pass my ImageManager around my whole program from one instance of it.
Board::Board(){
ImageManager &imgr;
//e.GetManager().AddResourceDirectory("images/");
//error checking, images/ is indeed in the vector
//std::cout << imgr.GetResourceDirectory()[0];
//gameBoard.setTexture(e.GetManager().GetImage("t3board.png"));
}
the semicolon is highlighted, saying "the variable imgr requires an intitializer". I'm sorry i'm not getting this, but it's just not coming to me. In Engine.h, under public, I have declared ImageManager imgr;. What would be the correct way to do this?
#include "stdafx.h"
#include "Board.h"
Board::Board(ImageManager &im) : imgr(im){
im.GetManager().AddResourceDirectory("images/");
//error checking, images/ is indeed in the vector
//std::cout << imgr.GetResourceDirectory()[0];
//gameBoard.setTexture(e.GetManager().GetImage("t3board.png"));
}
"im" is underlined, saying that im has no member GetManager(). This is because the compiler isn't acually seeing im as an ImageManager object, correct? What do I do from here?
Oh wow, it is definitely a Monday.. GetManager() was what I had in my Engine in my other failed attempt to solve this. Anyways, if I declare the actual imgr, how do I pass that off as a constructor when I create a board object?
I.e. in Engine.h I declare Board board:
So is &imgr the same imgr that was declared in the previous line? Also, how do I declare a Board object in Engine? Because I used to just have Board board; which makes an object, but with my modified constructor how do I declare this object?
In short, line 24 is trying to create a classwide Board object in my Engine class. I could do this before without using a constructor, but now I have to pass an ImageManager parameter through board's constructor, so board becomes not an object