隐式声明函数错误C ++

时间:2015-01-29 04:20:25

标签: c++

我在编译C ++文件时遇到问题。 这是我得到的错误:

此行有多个标记      - 未找到成员声明      - 隐式声明的定义' InsultGenerator :: InsultGenerator(const InsultGenerator&)'

我使用MinGW作为我的编译器。

这是C ++代码:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Insultgenerator_0hl14.h"

using namespace std;

FileException::FileException(const string& m) : message(m){}

string& FileException::what(){ return message;}

NumInsultsOutOfBounds::NumInsultsOutOfBounds(const string& m) : message(m){}

string& NumInsultsOutOfBounds::what(){ return message;}

InsultGenerator::InsultGenerator(const InsultGenerator& ) {}

void InsultGenerator::initialize() const{
int cols(0);
string x;

string filename("InsultsSource.txt");
ifstream file(filename.c_str());

if(file.fail()){
    throw FileException("File not read.");
}
 while(file >> x){

 }}

//vector<string> InsultGenerator::talkToMe() const{

  //    };//end talkToMe

  //    vector<string> InsultGenerator::generate(const int n) const{

   //   };//end generate

//int InsultGenerator::generateAndSave(const string filename, const int n)           const{

//};//end generateAndSave

这是头文件:

#ifndef INSULTGENERATOR_0HL14_H_
#define INSULTGENERATOR_0HL14_H_

#include <string>
#include <vector>

using namespace std;

class InsultGenerator{
public:
InsultGenerator(vector<string>);
void initialize() const;
string talkToMe() const;
vector<string> generate(const int) const;
int generateAndSave (const string, const int) const;

private:
vector<string> colA;
vector<string> colB;
vector<string> colC;
};

class FileException{
public:
FileException(const string&);
string& what();
private:
string message;
};

class NumInsultsOutOfBounds{
public:
NumInsultsOutOfBounds(const string &);
string& what();
private:
string message;
};

#endif

2 个答案:

答案 0 :(得分:4)

您正在实现InsultGenerator的复制构造函数,尽管您尚未声明它。

InsultGenerator(const InsultGenerator& );添加到InsultGenerator课程。 像这样:

class InsultGenerator
{
public:
    InsultGenerator(vector<string>); // also better remove that one since I don't
                                     // think you have implemented it

    InsultGenerator(const InsultGenerator &); // here
    void initialize() const;
    string talkToMe() const;
    vector<string> generate(const int) const;
    int generateAndSave (const string, const int) const;
private:
    vector<string> colA;
    vector<string> colB;
    vector<string> colC;
};

答案 1 :(得分:0)

编辑:

   class InsultGenerator
    {
    public:
        InsultGenerator(vector<string>); // Remove this line.
        InsultGenerator(const InsultGenerator &); // Add this line.
        void initialize() const;
        string talkToMe() const;
     ......
    }