#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);
}
定義...C++ 11リンカエラーVS17
#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はまだリンカによってエラーを取得:
LNK2019未解決の外部シンボル「パブリック:ブール__thiscall ストレージ:: writeFile(クラスstd :: basic_string、クラスstd :: allocator>、クラスAFile *) " (?? $ writeFile @ VAFile @@@ Storage @@ QAE_NV?$ basic_string @ DU?$ char_traits @ D @ std @@ V ?$ allocator @ D @ 2 @@ std @@ PAVAFile @@@ Z) 関数内_Main
コードが正しく表示されているのはなぜですか。クラス内のメソッドの一般的な定義とメソッドに渡すクラス型を制約しようとするIm AFaseはABaseから継承されています。
アバースは抽象クラスです。メインで
簡単な利用法:そう
template
bool Storage::writeFile<AFile>(string fileName,
enable_if<is_base_of<ABase, AFile>::value, AFile>::type* data);
コンパイラ:
Storage* s = new Storage("C:\\aPath...");
AFile* afile = new AFile();
s->writeFile<AFile>("a.txt", afile);
s = Storageのオブジェクト –
Um ...まず、関数が実際にはクラスメンバ(クラス 'Storage'のメンバ)であることを示すエラーメッセージが表示されます。しかし、あなたの宣言も定義も、それをクラスのメンバーとして定義していません。どうして?第二に、それはどのように "使用"と見なされますか?あなたの "使用法"に 'writeFile'の言及はありません。 – AnT
質問が更新されました。私が行ったことすべて... –