Main.cpp
#include "SelectionSort.h"
using namespace std;
int main() {
SelectionSort<int> sorterInt;
int test_array[20];
sorterInt.stuffNum(&test_array, 20, 1, 200);
}
SelectionSort.h
using namespace std;
template <typename T>
class SelectionSort {
public:
void stuffNum(T *object, int size, int min, int max)
{
for(int i = 0; i < size; i++)
{
(*object)[i] = 5;
}
}
SelectionSort<int> sorterInt;
int test_array[20];
sorterInt.stuffNum(&test_array, 20, 1, 200);
您的模板具有int类型,因此您的方法采用int*作为参数。你写了&test_array类型为int*[20]的用户,因为您发送了数组的地址。
所以只需删除&
sorterInt.stuffNum(test_array, 20, 1, 200);
您需要更好地理解指针。
编辑:(阅读评论(
(*object)[i] = 5;
在这里你应该像这个一样删除*和((
object[i] = 5;
这里有更多的医生什么是阵法腐朽?