未定义的引用'FileReader :: FileReader()'

问题描述:

任何人都可以请帮我修复我的代码,以便我可以编译它。未定义的引用'FileReader :: FileReader()'

当我编译一个错误消息“未定义的引用'FileReader :: FileReader()'”出现。

#ifndef SUBFILEREADER_H 
#define SUBFILEREADER_H 
#include <string> 
#include "FileReader.h" 

using namespace std; 

class SubFileReader : public FileReader 
{ 
    string sS; 
    int iS; 
    string sHoldS; 
    string siS; 

public: 
    SubFileReader(); 
    string readFile(string file); 
}; 
#endif 

#include "SubFileReader.h" 
#include "FileReader.h" 
#include <iostream> 
#include <string> 
#include <fstream> 
#include <sstream> 

using namespace std; 

/** 
* class SubFileReader, reads a file and prints it to stdout. 
* 
* @author Alvin Benedicto 
* @version 2.12.10 
*/ 
SubFileReader::SubFileReader() : FileReader() 
{ 
    sS = "asdf"; 
    iS = 0; 
    siS = ""; 
} 

/** 
* readFile, reads the content of the file into a string and prints the string to standard output. 
* @ param file, string file to be read. 
*/ 
string SubFileReader::readFile(string file) 
{ 
    stringstream ints; 

    ifstream in(file.c_str()); 
    while(getline(in, sS)) 
    { 
     ints << iS++; 
     ints >> siS; 

     sHoldS += sS + " " + siS + "\n"; 
    } 
    return sS; 
} 

#include "SubFileReader.h" 
#include "FileReader.h" 
#include <string> 
#include <fstream> 
#include <iostream> 
using namespace std; 

/** 
* main, to test the methods 
* @author Alvin Benedicto 
* @version 2.12.10 
*/ 
int main(int argc, char *argv[]) 
{ 
    string str; 
    SubFileReader *yz = new SubFileReader(); 
    str = argv[1]; 

    ofstream out("MainSubFileReaderTest.txt"); 
    //cout << xy->readFile(str) << endl; 
    out << yz->readFile(str); 
} 
+0

你能告诉我们FileReader.h和.cpp吗? – bjskishore123 2010-12-03 17:59:11

+0

请使用代码按钮进行格式化。只有我有足够的声望,我才会编辑。 – Srikanth 2010-12-03 18:02:14

你需要或者编译FileReader.cpp,或链接到哪个库包含的FileReader::FileReader()定义。

顺便说一句,您不需要在客户端代码中使用#include FileReader.h。