Apr 10, 2010 at 8:10pm UTC
Hello, i am new to this forum and trying to create a merge sort function.
Upon testing, i get this error.
" error: no matching function for call to 'merge(List&, List&)' "
when i try to call it in the main, this is how it looks
2 3 4
...(bunch of code that fills both lists above with values)...
List merged_list = merge( list1, list2);
in my list.h file, it looks like this
const List* one, const List* two );
and here is the list.cpp
2 3 4 5
const List* one, const List* two )
...(bunch of code for merge sorting)....
what am i doing wrong? thanks!
Last edited on
Apr 10, 2010 at 8:11pm UTC
Apr 10, 2010 at 8:24pm UTC
I'm not sure if it will actually change anything because I never pass by pointer, but there is no call for REFERENCE parameter, not pointer. Try changing those pointers in your arg list to references and see what happens.
Apr 10, 2010 at 8:33pm UTC
the same thing happened :(.
I want to write it in a way so that the function has two parameters, that both point to two seperate lists, and i want it to return a pointer to the new merged list.
Apr 10, 2010 at 8:35pm UTC
Hm. Maybe it's a problem with the includes. I hate to ask such a simple question but did you link the merge implementation with your main source code? (I gotta be missing something simple but for the life of me I can't think of it.)
Apr 10, 2010 at 8:38pm UTC
no i did not.
my merge implementation is in my list.cpp. and in my main, i used iostream and list.h as my include. All function calls to other functions in the list.cpp work except this one. :(
Apr 10, 2010 at 9:22pm UTC
You aren't passing the addresses of the List objects list1 and list2. Use &list1 and &list2 when calling the function and see if that works.
Apr 10, 2010 at 9:56pm UTC
hmm, i did that and i get this error now
" undefined reference to 'List::merge(List const*, List,const*)' "
Apr 10, 2010 at 9:59pm UTC
Well that solved one problem. Is merge a member of your list class?
Apr 10, 2010 at 10:08pm UTC
ahh no it wasn't. that fixed my problem. thanks guys!