C++ Can't Return A Vector of Textures : <p>I have a class that keeps track of objects I've declared. This class also has a vector as a member. I add textures through a function (probably, there is a leak). I am probably doing a mistake about c++ itself, not sfml.</p>

<p>in Item.h:</p>

<pre><code>    #ifndef ITEM_H
    #define ITEM_H

    class ItemTexture {
        public:
            static std::vector&lt;ItemTexture*&gt; textures;
            std::vector&lt;sf::Texture*&gt; variation;
            ItemTexture(std::string file);
            void addTexture(std::string file);
            static sf::Texture getTexture(int id, int no) {
                return *textures[id]-&gt;variation[no]; //Program crashes here
            }
            static void declare_textures();
    };

#endif
</code></pre>

<p>in the Item.cpp:</p>

<pre><code>#include "Item.h"
std::vector&lt;ItemTexture*&gt; ItemTexture::textures;
ItemTexture::ItemTexture(std::string file)
{
    sf::Texture *tex = new sf::Texture;
    tex-&gt;setSmooth(false);
    tex-&gt;loadFromFile(file);
    variation.push_back(tex);
    textures.push_back(this);
    delete tex;
}
void ItemTexture::addTexture(std::string file)
{
    sf::Texture *tex = new sf::Texture;
    tex-&gt;setSmooth(false);
    tex-&gt;loadFromFile(file);
    variation.push_back(tex);
    delete tex;
}
</code></pre>

<p>This doesn't give any error messages, program crashes at the line return *textures[id]->variation[no];</p>
