No call to the corresponding function to the class member

I have implemented a general list and I am trying to extract data from a specific position in the list. umm ... but I get an error: no suitable function to call "List :: retrieve (int &, Record &)" The following is the main.cpp code and a fragment of the function from the 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; } 

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; } 

For the full code:

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

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

PS I'm just learning the basics, and the code may not be ideal for a large-scale reusable module. At this point, it just has to work.

thanks

+4
source share
2 answers

data you are trying to pass as the second retrieve argument is of type Record .

The second retrieve parameter is of type List_entry , not Record .

When the compiler says โ€œthere is no corresponding functionโ€, this usually means that it found a function with the name that you used, but one or more of the arguments that you are trying to pass to this function are of the wrong type, or you are trying to pass the wrong number of arguments to the function.

+6
source

The error "Lack of a suitable function to call [...]" usually means "I cannot find a function that you can call with the following arguments." This can mean many things - either you mistakenly wrote the name of the function, or arguments of the wrong type, or you are trying to call a non-const member function in a const object, etc. Usually an error gives you some more detail about what went wrong, including the functions that he was trying to map, as well as the types of arguments that were actually found on the call site. Templates can make it harder to read, but with little time, you can usually learn to read them.

For this code, the second argument to the retrieve function is of type List_entry, which is the template parameter for List. In your main function, you instantiate the list, so List_entry is int in this case. However, you are trying to find a record that (I suppose) is not int. If you either modify the code to try to find an int, or to make a List List, this problem should go away.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1334025/


All Articles