没有匹配函数调用类成员

Cip*_*her 5 c++

我已经实现了一个通用列表,我试图从列表中的某个位置检索数据.嗯...但是我收到一个错误:没有匹配函数来调用'List :: retrieve(int&,Record&)'下面是main.cpp的代码和一个从List.h中检索的函数片段.#include

Main.cpp的

#include <iostream>
#include "List.h"    
#include "Key.h"
using namespace std;
typedef Key Record;
int main()
{
    int n;
    int p=3;
    List<int> the_list;
    Record data;
    cout<<"Enter the number of records to be stored. "<<endl;
    cin>>n;
    for(int i=0;i<n;i=i++)
    {
    the_list.insert(i,i);
    }
    cout<<the_list.size();
    the_list.retrieve(p, data);
    cout<<"Record value: "<<data;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

List.h

Error_code retrieve(int position, List_entry &x)const
    {
    if(empty()) return underflow;
    if(position<0 || position>count) return range_error;
    x=entry[position];
    return success;
    }
Run Code Online (Sandbox Code Playgroud)

完整代码:

Main.cpp:http://pastebin.com/UrBPzPvi

List.h:http://pastebin.com/7tcbSuQu

PS我只是学习基础知识,对于大规模可重用模块,代码可能并不完美.在这个阶段,它只需要工作.

谢谢

Jam*_*lis 9

data,你试图作为第二个参数传递retrieve,是类型Record.

第二个参数retrieve是类型List_entry,而不是Record.

当编译器说"没有匹配的函数"时,这通常意味着它找到了一个带有你使用的名字的函数,但是你试图传递给该函数的一个或多个参数是错误的类型,或者你试图通过函数的参数个数错误.