我在我的fileType.h中有這段代碼。鏈接器抱怨關於vtable的undefined參考
class FileType{
private:
School* m_school;
string m_fileFormat;
const string m_cfgFile;
const string m_inputFile;
public:
FileType(string p_fileFormat, string p_cfgFile, string p_inputFile):
m_fileFormat(p_fileFormat), m_cfgFile(p_cfgFile), m_inputFile(p_inputFile) {};
virtual bool parseInputFile();
virtual bool writeOutputFile(const School& m_school);
virtual bool checkFormat(); // TBD -- used to check the format of the input file
virtual bool checkConstraints(); // TBD -- used to check things like only +ve 12 digit in the ID etc
virtual ~FileType();
};
class XmlType:public FileType{
public:
XmlType(string p_fileFormat, string p_cfgFile, string p_inputFile):
FileType(p_fileFormat, p_cfgFile, p_inputFile) {};
virtual bool parseInputFile();
virtual bool writeOutputFile(const School& m_school);
virtual bool checkFormat(); // TBD -- used to check the format of the input file
virtual bool checkConstraints(); // TBD -- used to check things like only +ve 11 digit in the ID etc
};
class CsvType:public FileType{
public:
CsvType(string p_fileFormat, string p_cfgFile, string p_inputFile):
FileType(p_fileFormat, p_cfgFile, p_inputFile) {};
virtual bool parseInputFile();
virtual bool writeOutputFile(const School& m_school);
virtual bool checkFormat(); // TBD -- used to check the format of the input file
virtual bool checkConstraints(); // TBD -- used to check things like only +ve 11 digit in the ID etc
};
在我主我把:
#include "fileType.h"
FileType *inputFilePtr, *outputFilePtr;
string stringOne, stringTwo, stringThree;
inputFilePtr = new CsvType(stringOne, stringTwo, stringThree);
現在我的鏈接告訴我,我不知道有關構造函數的符號:
/cygdrive/c/Users/Owner/AppData/Local/Temp/cclieUAi.o:main.cpp :(。text $ _ZN7CsvTypeC1ESsSsSs [CsvType :: CsvType(std :: basic_string,std :: allocator>,std :: basic_st環,性病::分配器>,的std :: basic_string的,標準::分配器>)] + 0x1bf):未定義參照vtable for CsvType' /cygdrive/c/Users/Owner/AppData/Local/Temp/cclieUAi.o:main.cpp:(.text$_ZN8FileTypeC2ESsSsSs[FileType::FileType(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x3a): undefined reference to
虛函數表爲文件類型」 collect2:LD返回1個退出狀態
我試圖使虛設構造有兩個整數,什麼都不做。這工作,但一旦我把字符串,這失敗了。任何想法有什麼不對?
可能重複[未定義引用的vtable(http://stackoverflow.com/questions/3065154/undefined-reference-to-vtable) –