Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Undefined reference to ResourceHolder when following "SFML Game development"  (Read 4168 times)

0 Members and 1 Guest are viewing this topic.

AnhBao

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Hello everyone. I am currently using Code::Block 20.03 and C++ 17.I have been using SFML for nearly 3 months. I found Laurent's book "SFML Game Development" one week ago. So in page 63 there is code lines look like this:
"
     Aircraft::Aircraft(Type type, const TextureHolder& textures):
     mType(type), mSprite(textures.get(toTextureID(type)))
     {
     }
"
I made console project, linked to SFML library.
I use .hpp files for headers and .cpp files for either main or class function definitions, I do not use .inl files.
But as soon as I compile it said
"
     D:\2.Tin\Project\Plane_shooter\Aicraft.cpp|20|undefined reference to `ResourceHolder<sf::Texture,
     Textures::ID>::get(Textures::ID) const'|
     ||error: ld returned 1 exit status|
"
This is in the file "Aircraft.cpp". Following are #include of the files:
Aircraft.cpp : #include "Aircraft.hpp"
Aircraft.hpp : #include "ResourceHolder.hpp" (template class for storing resources such as fonts, textures, ... It has a public member function "template <typename Resource, typename Identifier> const Resource& get(Identifier id) const"
                    #include "ResourceIdentifiers.hpp" (which consists a namespace Textures {enum class ID{...} };
Can you help me? I do not think i can figure out the problem myself.
Im sorry i uploaded this post in general but i think its just something to do with graphics module since I have not dealt with others.
Any help and comment would be appreciated, thank you.

AnhBao

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
I solved this. There is an old post about the exact error. Turns out I have to define member functions inside header files when I use template, or I can use .inl file, but not .cpp file.
" http://www.cplusplus.com/forum/general/122601/ "
This is the post.

 

anything