0

Here's the class containing the templated objects:

class ResourceManager
{
    public:
        ResourceManager(DebugMenu& debugMenu);

    private:
        ResourceHolder<sf::Texture, Textures::Id>           m_textureHolder;
        ResourceHolder<sf::Font, Fonts::Id>                 m_fontHolder;
        ResourceHolder<sf::SoundBuffer, SoundEffect::Id>    m_soundBuffer;
};

And ResourceHolder.hpp (cut down significantly):

template <typename Resource, typename Identifier>
    class ResourceHolder
    {
    public:
        ResourceHolder(DebugMenu& debugMenu);

    private:
        DebugMenu* m_debugMenuContext;
    };

Now what I'm trying to do is use an initializer list to pass the DebugMenu reference to all of the ResourceHolders (because they need it for the DebugMenu context). Like so:

ResourceManager::ResourceManager(DebugMenu& debugMenu) :
    m_textureHolder(ResourceHolder<sf::Texture, Textures::Id>(debugMenu)),
    m_fontHolder(ResourceHolder<sf::Font, Fonts::Id>(debugMenu)),
    m_soundBuffer(ResourceHolder<sf::SoundBuffer, SoundEffect::Id>(debugMenu)) {}

But I'm getting an error for each initialization:

Undefined symbols for architecture x86_64:
  "Shock::ResourceHolder<sf::SoundBuffer, Shock::SoundEffect::Id>::ResourceHolder(Shock::DebugMenu&)", referenced from:
      Shock::ResourceManager::ResourceManager(Shock::DebugMenu&) in ResourceManager.o
  "Shock::ResourceHolder<sf::Font, Shock::Fonts::Id>::ResourceHolder(Shock::DebugMenu&)", referenced from:
      Shock::ResourceManager::ResourceManager(Shock::DebugMenu&) in ResourceManager.o
  "Shock::ResourceHolder<sf::Texture, Shock::Textures::Id>::ResourceHolder(Shock::DebugMenu&)", referenced from:
      Shock::ResourceManager::ResourceManager(Shock::DebugMenu&) in ResourceManager.o
ld: symbol(s) not found for architecture x86_64

I'm at a bit of a loss what the problem could be, so any help would be greatly appreciated. Thanks.

Peter
  • 328
  • 4
  • 18
  • 2
    Did you define the constructor (i.e. `ResourceHolder::ResourceHolder`) in another file like `ResourceHolder.cpp`? – songyuanyao Dec 04 '16 at 01:58
  • Yes, the definition of ResourceHolder's constructor is in ResourceHolder.cpp – Peter Dec 04 '16 at 01:59
  • Why are you creating a temporary and then copying it? You should just do `m_textureHolder(debugMenu)` instead of `m_textureHolder(ResourceHolder(debugMenu))`. That won't solve the problem you're having, but it will make things more readable. – Miles Budnek Dec 04 '16 at 02:00
  • @MilesBudnek That's how I had it originally, but I made an edit because I had a brain fart and thought it would make a difference, but like you said it doesn't. – Peter Dec 04 '16 at 02:01
  • 1
    See the linked question for an explanation why `ResourceHolder`s constructor must be defined in the header file. – Sam Varshavchik Dec 04 '16 at 02:02

0 Answers0