I'd advise to learn more about C++(11) and the STL.
Then you would hopefully learn that one should not use 'raw' pointers but smart pointers, like std::shared_ptr or std::unique_ptr
For you problem, you have to allocate the resource with the new keyword otherwise the memory will get allocated on the stack and would be released as soon as you go into the next for loop iteration.
std::vector<sf::Image*> images;
for(unsigned int i=0; i < 10; ++i)
{
sf::Image* temp = new sf::Image();
temp.LoadFromFile("image.png");
images.push_back(temp);
}
for(unsigned int i=0; i < images.size(); ++i)
delete image.at(i);
I'd also suggest not to use SFML 1.6 anymore, mainly because it won't run on most of the computers with ATI graphic cards.
And if you switch to SFML 2 you could then also use the Thor library (https://github.com/Bromeon/Thor) for resource management, although the API will change in the near future.
std::vector<sf::Image*> images;
for(unsigned int i=0; i < 10; ++i)
{
sf::Image* temp = new sf::Image();
temp.LoadFromFile("image.png");
images.push_back(temp);
}
for(unsigned int i=0; i < images.size(); ++i)
delete image.at(i);
I would prefer doing it this way:
std::vector<sf::Image*> images;
for (unsigned int i=0; i < 10; ++i) {
images.push_back (new sf::Image());
images.back()->loadFromFile ("image.png");
}
make shure your vector doesn´t go off scope