I have run into a weird unresolved external symbol error with this class. I have a C++ library based on Qt where LIBDATASHARED_EXPORT
is an alias for __declspec(dllexport)
or __declspec(dllimport)
.
class LIBDATASHARED_EXPORT SaveFile
{
class Index
{
public:
operator bool() const; //<--- defined in cpp
};
public:
template<typename T> load()
{
Index idx;
if(idx) //<--- complains about unresolved symbol...
{
}
}
};
When I use this in another project where I link with the library I get the unresolved external symbol
about the SaveFile::Index::operator bool() const
when instantiating the template method. When I put the definition of SaveFile::Index::operator bool() const
in the header it works fine. The definition of SaveFile::Index::operator bool() const
is indeed in the same .cpp file as the rest of the class' definitions so it should be defined at the point of instantiation.
What is the problem here and how do I fix it?