本文介绍了隐式声明函数错误C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在编译我的C ++文件时遇到问题。
这是我得到的错误:
I'm having an issue compiling my C++ file.This is the error I get:
此行有多个标记
- 未找到成员声明
- 隐式声明'InsultGenerator :: InsultGenerator(const InsultGenerator&)'
Multiple markers at this line - Member declaration not found - definition of implicitly-declared 'InsultGenerator::InsultGenerator(const InsultGenerator&)'
我使用MinGW作为我的编译器。
I'm using MinGW as my compiler.
以下是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
推荐答案
正在实施 InsultGenerator
的副本构造函数,虽然您尚未声明它。
You are implementing InsultGenerator
's copy-constructor although you haven't declared it.
添加 InsultGenerator(const InsultGenerator&);
到您的 InsultGenerator
类。
像这样:
Add InsultGenerator(const InsultGenerator& );
to your InsultGenerator
class.Like so:
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;
};
这篇关于隐式声明函数错误C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!