我收到了那条消息
no matching function for call to 'main()::MySeqInFileEnumerator::MySeqInFileEnumerator(const char [10])'
当我做我的字符串匹配工作时。我必须方法覆盖现有代码。我必须打开一个输入文本,并从中创建一个抽象文件,然后我必须做一个乐观的 linsearch。
#include <iostream>
#include "linsearch.hpp"
#include "seqinfileenumerator.hpp"
using namespace std;
struct MyPair
{
int azon;
int osszeg;
friend ifstream& operator>>(ifstream& f, MyPair& df);
};
ifstream& operator>>(ifstream& f, MyPair& df)
{
f >> df.azon >> df.osszeg;
return f;
}`enter code here`
int main()
{
class MyLinSearch: public LinSearch <int, true>
{
bool Cond(const int& e) const
{
return e<=-100000;
}
};
class MySeqInFileEnumerator: public SeqInFileEnumerator <MyPair>
{
void Next()
{
MyPair dx;
f >> dx;
df.azon=dx.azon;
df.osszeg=dx.osszeg;
while(dx.azon==df.azon)
{
dx.osszeg+=df.osszeg;
f >> dx;
}
}
};
MyLinSearch pr;
MySeqInFileEnumerator t("input.txt");
pr.AddEnumerator(&t);
pr.Run();
if (pr.Found())
{
cout << "false " << endl;
}
else cout << "true" << endl;
return 0;
}
最佳答案
正如错误消息所说,该类没有采用字符串的构造函数;但是您尝试将其中一个与
MySeqInFileEnumerator t("input.txt");
也许基类有合适的构造函数?在这种情况下,您需要转发参数:
explicit MySeqInFileEnumerator(char const * name) :
SeqInFileEnumerator<MyPair>(name)
{}
关于c++ - "no matching function"初始化类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20357835/