C++ "No matching function for call"错误
C++ "No matching function for call" error
我正在使用MinGW编译器。我不明白为什么我会收到错误。
错误:
Multiple markers at this line
- candidate is:
- no matching function for call to 'InsultGenerator::InsultGenerator()'
- Line breakpoint: Insultgenerator_0hl14.cpp [line: 22]
这是 cpp 文件:
#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);
InsultGenerator t1;
string insults;
string filename("InsultsSource.txt");
ifstream file(filename.c_str());
if(file.fail()){
throw FileException("File not read.");
}
while(file >> insults){
if(cols==0){
t1.colA.push_back(insults);
cols++;
} else if(cols==1){
t1.colB.push_back(insults);
cols++;
}else{
t1.colC.push_back(insults);
cols= cols -2;
}
}
for (int i=0;i<50;i++){
cout << i << t1.colA[i];
}
}
这是头文件:
#ifndef INSULTGENERATOR_0HL14_H_
#define INSULTGENERATOR_0HL14_H_
#include <string>
#include <vector>
using namespace std;
class InsultGenerator{
public:
// InsultGenerator(vector<string>);
InsultGenerator(const InsultGenerator &);
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
:InsultGenerator(const InsultGenerator &);
,但它有参数。您需要一个没有参数的构造函数,以便语句InsultGenerator t1;
可以正确调用相应的构造函数。
因为您没有InsultGenerator
对象的构造器。在头文件中,添加InsultGenerator();
,在 CPP 文件中,添加
InsultGenerator::InsultGenerator() { }
相关文章:
- "error: no matching function for call to"构造函数错误
- "no matching function for call to 'Vector::Vector'"错误
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 学习 c++,编译错误"no matching function for call"
- 结构错误:"no matching function for call to "
- 创建函数变体向量时"No matching function for call"错误
- 编译时二叉搜索树错误的反向迭代器表示"no matching function call for operator=()"
- 如果子类中没有构造函数方法,则错误"no matching function for call to 'LGame::LGame(String&)'"
- 提升多精度浮点数128:标准::exp错误:'no matching function for call'
- C++字符串.替换生成"No matching function for call"错误
- "No Matching Function for call"错误
- 重载<运算符在另一个类中使用时"no matching function for call"错误
- C++ "No matching function for call"错误
- 为什么OpenSSL给我一个"called a function you should not call"错误?
- 海湾合作委员会"no matching function for call.."错误
- 模板函数给出"no matching function for call"错误
- Pjsip new-call错误…无法找到默认的音频设备(PJMEDIA_EAUD_NODEFDEV)
- 使用提升::绑定时"no match for call"错误
- C++:莫名其妙"pure virtual function call"错误
- C++中多线程处理时出现"no matching function call"错误