Declaration inside bmd2fileio.h
class bmd2File {
public:
template <typename T>
void write(const T & t) const throw (bmd2Exception);
Definition inside bmd2fileio.cpp
#include "bmd2fileio.h"
...
template <typename T>
void bmd2File::write(const T & t) const throw (bmd2Exception)
{
#ifdef _WIN32
LPDWORD lpNumberOfBytesWritten;
bool written = WriteFile(this->handle,
t,
sizeof(T),
lpNumberOfBytesWritten,
0);
if (!written)
{
printf("Not written.");
} else {
printf("Written.");
}
#else
#endif
}
The (failed) call inside main.cpp:
#include "bmd2fileio.h"
...
const std::string data = "meow";
std::auto_ptr<bmd2File> myBmdFile(new bmd2File(fileName));
myBmdFile->write(data);
It won't link with the following error:
undefined reference to `bmd2File::write(std::string const&) const'
I thought that would resolve to std::string such that the linker would find my function just fine... but not the case. Doh!