2010-12-03 19 views
0

誰でもコンパイルできるようにコードを修正してください。'FileReader :: FileReader()'への未定義の参照

コンパイル時に、「FileReader :: FileReader()への未定義の参照」というエラーメッセージが表示されます。あなたはどちらのライブラリにFileReader.cpp、またはリンクをコンパイルするか必要

#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

+0

コードボタンでフォーマットしてください。私は十分な評判がある場合にのみ編集したでしょう。 – Srikanth

+0

コンパイルに使用しているコマンドが役立つかもしれません。これは、コードの問題よりコンパイルの問題のほうが聞こえるためです。 – Herms

答えて

3

FileReader::FileReader()の定義が含まれています。

なお、お客様のクライアントコードには、#include FileReader.hは必要ありません。

+0

実際には、filereaderクラスは正常に動作します。私はちょうどサブクラスをコンパイルするprobemを持っています。 – John

+0

しかし、あなたはFileReaderの場所をコンパイラに教えていますか?それは、この答えの一部である "ライブラリへのリンク"です。 – Herms

+0

助けてくれてありがとう、それは今コンパイルします。 – John

関連する問題