I've been experiencing a linking issue on a project, and I've found a workaround I can't really explain.
I had this kind of class and I was getting an unresolved external symbol on getType<>()
, which was correctly imported from another lib.
MyClass( CustomType& iType = getType<OtherClass>() )
{...}
The workaround found is a little less reusable, but still satisfies conviniently my use case for now. Same linker properties, etc.
MyClass( )
: mType( getType<OtherClass>() )
{...}
- What difference does it make to set a member variable with a default argument value or through the initializer list?
- Is there a difference of scope? e.g. could it be because
otherClass
andgetType<>()
exist in different namespaces?
EDIT: Declaration of getType:
template<typename type>
CustomType* getType() {
static CustomType* oType = getType(typeid(type));
return oType;
}
Linker error:
MyClass.obj : error LNK2019: unresolved external symbol "public: class CustomType * __thiscall Metadata::getType<class OtherClass>(void)" ...