#include <iostream>
#include <fstream>
#include <type_traits>
#include <Windows.h>
#include "abase.h"
using namespace std;
class Storage {
string _path;
public:
Storage(string path);
~Storage() = default;
template <typename T >
bool writeFile(string fileName,
typename enable_if<is_base_of<ABase, T>::value, T >::type* data);
}
Definition...
#include "storage.h"
Storage::Storage(string path)
{
this->_path = path;
}
template <typename T >
bool Storage::writeFile(string fileName,
typename enable_if<is_base_of<ABase, T>::value, T >::type* data){
return true;
}
Im still getting error by Linker:
LNK2019 unresolved external symbol "public: bool __thiscall Storage::writeFile(class std::basic_string,class std::allocator >,class AFile*)" (??$writeFile@VAFile@@@Storage@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVAFile@@@Z) referenced in function _main
Why am i getting it if code is looking right. Its generic definition of method in a class and Im trying to constrain class type passing to the method. And the AFile is inherited from ABase.
ABase is abstract class.
Simple usage in main:
Storage* s = new Storage("C:\\aPath...");
AFile* afile = new AFile();
s->writeFile<AFile>("a.txt", afile);