首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对“FileReader ::FileReader()”的未定义引用

对“FileReader ::FileReader()”的未定义引用
EN

Stack Overflow用户
提问于 2010-12-03 17:34:25
回答 1查看 779关注 0票数 0

有人能帮我修一下我的代码吗?这样我就可以编译了。

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

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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;
}

代码语言:javascript
复制
#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);
}
EN

回答 1

Stack Overflow用户

发布于 2010-12-03 17:56:01

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

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4348211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档