I have this class with templated functions within it.
Header file
class Entity {
public:
Entity();
template<typename T>
void addComponent();
};
Source file
Entity::Entity() {}
template<typename T>
void Entity::addComponent() {}
Main file
int main()
{
auto e = Entity();
e.addComponent<Transform>();
}
When compiling it returns this error and I have not idea why. People mention the declared function and the one implemented are not the same but I am not sure if that is the case for this.
main.cpp:(.text+0x1c): undefined reference to `void Entity::addComponent<Transform>()'
/usr/bin/ld: main.cpp:(.text+0x28): undefined reference to `void Entity::addComponent<Sprite>()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:21: build] Error 1