ParaToxic Posted December 30, 2012 Posted December 30, 2012 Hello guys, I had a little idea for a data loader and saver.Normal functions uses void pointers or just void to write/read data from a binary fstream object. But why don't you use templates for that ?? So I used them, but it doesn't work actually ( I'm not the pro with templates...so...) Maybe someone can help me.. I get a linker error when I want to call the write function. #ifndef ISERIALIZER_H_ #define ISERIALIZER_H_ #include <iostream> #include <fstream> #include "GlobalDefine.h" class ISerializer { public: ISerializer() : fileloaded(false) { } ~ISerializer() { } std::fstream filestream; bool fileloaded; IResult Load(std::string filename); IResult Save(); template<typename T> void Read(T* out); template<typename T> void Write(T in); }; #endif #include "ISerializer.h" IResult ISerializer::Load(std::string filename) { filestream.open(filename.c_str(),std::ios::in | std::ios::binary); if(!filestream.bad()) { return IRESULT_OK; } else { return IRESULT_ERROR; } } IResult ISerializer::Save() { filestream.close(); fileloaded = false; return IRESULT_OK; } template<typename T> void ISerializer::Read(T* out) { if(fileloaded) { filestream.read(&out,sizeof(T)); } } template<typename T> void ISerializer::Write(T in) { if(fileloaded) { filestream.write(in,sizeof(T)); } } Thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.