Hi,
I am trying to create a class that can write any type of object to a
file. I would like to use a template function which is a member of the
class. Something like:
class MyWriter
{
public:
...
template <class T>
void write(const T& buffer);
...
protected:
...
ofstream ofs;
...
};
template <class T>
void MyWriter::write(const T& buffer)
{
ofs.write((char*)(&buffer), sizeof(buffer));
}
The idea is that the function will be able to determine the size of the
object, so the user of the class will not have to pass the size to the
function. A possible use would be:
MyWriter writer;
MySpecialClass writeMe;
....
writer.write(writeMe);
This code does not link and i get an 'unresolved external' message. Can
anyone please help me get this resolved?