c++ - "no matching function"初始化类

标签 c++

我收到了那条消息

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/

相关文章:

c++ - Visual Studio 2010 和 2012 中 STL 容器字节大小的差异

c++ - 编码可执行文件

java - 构造函数应该有 StoreStore 屏障吗?

c++ - 可以覆盖(隐藏)一个非虚方法但仍然从子类显式调用它吗?

c++ - MySQL异步?

c++ - 抛出对齐类型时出现 Clang 运行时错误。编译器错误?

c++ - 在C++中的 vector 内向 vector 添加元素

c++ - 我将 #include 指令放在我的 cpp 文件中还是包含的头文件中有关系吗?

c++ - 修剪连续的标准容器

c++ - MPI、C、派生类型、 vector 结构?