为什么此函数调用在函数外部而不在函数中?

时间:2015-11-25 06:44:41

标签: c++ function parameters compiler-errors

我在C ++代码中不断收到此错误

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&)’

我很奇怪为什么它不起作用,因为我在函数中有另一个函数调用,因为它已经完美地工作了

这是函数调用

的函数
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;
    }

如果我在排序之外调用change_the(nums, r, q),它就可以了。我无法弄清楚是什么抛弃它,特别是因为findmin函数在sort函数中工作正常并且具有几乎相同的参数。

我用10个整数数组调用sort函数。

sort(array_name, 9)

这是我的程序完全看起来的样子(我没有包含findmin函数)

#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)

我为数组赋值

然后我调用sort如上所示

感谢您的帮助!

最终编辑:我的问题是在定义实际函数本身之前,函数是在另一个函数中调用的。再次感谢

0 个答案:

没有答案