I keep getting this error in my C++ code
sort.cxx: In function ‘void sort(Item*, SizeType) [with Item = int, SizeType = int]’:
sort.cxx:89: instantiated from here
sort.cxx:17: error: no matching function for call to ‘change_the(int*&, int&, int&)’
It's strange to me why it's not working because I have another function call in the function that as been working perfectly
Here is the function with the function call
template <class Item, class SizeType>
void sort(Item nums[], SizeType input)
{
for(int r = 0; r < input - 2; r++)
{
int w = findmin(data, r, input);
change_the(nums, r, w);
}
}
And here is the called function giving me the errors
template <class Item, class SizeType>
void change_the(Item nums[], SizeType r, SizeType w)
{
int save = nums[r];
nums[r] = nums[j];
nums[j] = save;
}
If I call change_the(nums, r, q)
outside of sort, it works. I can't figure out what is throwing it off, especially because the findmin function works fine in the sort function and has nearly identical parameters.
I am calling the sort function with an array of 10 integers.
sort(array_name, 9)
Here is what my program looks like altogether (I didn't include findmin function)
#include <iostream>
using namespace std;
template <class Item, class SizeType>
void sort(Item nums[], SizeType input)
{
for(int r = 0; r < input - 2; r++)
{
int w = findmin(data, r, input);
change_the(nums, r, w);
}
}
template <class Item, class SizeType>
void change_the(Item nums[], SizeType r, SizeType w)
{
int save = nums[r];
nums[r] = nums[j];
nums[j] = save;
}
int main()
{
int array_name[9]
... I assign values to array_name at 0-9
sort(array_name, 10)
I assign values to the array
and then I call sort as shown above
Thanks for the help!
Final Edit: my problem was that the function was called in another function before the actual function itself was defined. Thanks again