Try to move the template definitions from Object.cpp to Object.h.
It is probably possible to instantiate these functions in Object.cpp, but only for specific types, like Choice*.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm having some trouble with my static template methods, specifically that the linker can't resolve them. I'm not sure why, because as I understand it, the compiler is supposed to write the methods. I have no problem resolving the class's non template methods, including static methods, which leads me to believe that the problem is specific to the template itself.
I'd appreciate any insight as to what the underlying problem is.
"Object.h" declaration
template <typename T>
static T FindObject(long UUID, std::vector<Object*>& Objs, bool crash = true);
template <typename T>
static T FindObject(std::string name, std::vector<Object*>& Objs, bool crash = true);
"Object.cpp" definition
template <typename T>
T Object::FindObject(long UUID, std::vector<Object*>& Objs, bool crash) {
// function body
}
template <typename T>
T Object::FindObject(std::string name, std::vector<Object*>& Objs, bool crash) {
// function body
}
Example call which fails to resolve:
bool Law::getChoiceActive(std::string name) {
return Object::FindObject<Choice*>(name, choice)->getSelected();
}
Try to move the template definitions from Object.cpp to Object.h.
It is probably possible to instantiate these functions in Object.cpp, but only for specific types, like Choice*.