I will try to explain the use of pointers generally:
(If you have doubts, feel free to add me on msn)
So, when you declare a sf::Image:
sf::Image img;
... you are allocating some memory, you can check how much using the function sizeof, like this:
sizeof(img); //sizeof(sf::Image) is also valid! Function returns size in bytes
When you do this:
sf::Image *img = new sf::Image;
...you are also allocating memory, pretty much the same way as for how much you care!
After either declaration, there is a sf::Image in your RAM, now you only need to be careful about how you use it!
With the first way, the object is bound to the created sf::Image memory address automaticly, and you may call its methods without further trouble!
Now on what comes to pointers:
A pointer is a variable too! But because a pointer holds as its value an address, its value can be anything in the RAM.
Because the pointer has this capacity to point at different adresses, you can play at will, as long as your data have integrity of course!
sf::Image img1,img2; //just two images
sf::Image *pImg = 0; //Points at nothing, the NULL
pImg = &img1; //& meaning address-of, now our pointer knows about img1;
pImg = &img2;//and now, it knows where the img2 is!
img1.LoadFromFile(""); // Calling a method normally
pImg->LoadFromFile("") //Calling a method from a pointer! This would call the LoadFromFile of img2!
(*pImg); //the symbol on the left makes the pointer behave like a normal object, so you could do:
(*pImg).LoadFromFile(""); //and still be calling img2 method!
&pImg; // The address of a pointer even lets you acess the raw bytes!
//You don't need to point at sf::Image created staticly!
pImg = new sf::Image(); //This just throws a sf::Image into memory, and keep its address for future reference!
delete pImg; //This will destroy permanently the sf::Image pImg is pointing to!
Now applying to the resource manager example:
In the vector, you keep a pointer instead of the actual sf::Image because you can later reference to it, instead of copying , which is faster!
and the resources will all be centralized, everything used it there, and thats good for your organization, specially when a lot of resources are used!
Imagine your search function like this:
sf::Image* ResourceManager::SearchImage(string SearchFileName){
for(unsigned int i = 0; i < ImageList.size(); i++){
if(ImageList[i].first == SearchFileName){ // first is the string , in the pair
return ImageList[i].second; //you return the pointer to the sf::Image you are holding
}
}
}
Where you called the function, you just got a fresh pointer:
use it normally as a sf::Image
Sprite.SetImage(*pointerObtained);
I hope this clarifies it a bit for you!