Pritesh Desai Pritesh Desai - 1 month ago 13
C++ Question

Cannot initialize a parameter of type 'int *' with an rvalue of type 'int (*)[20]'

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;


}
}

Answer
SelectionSort<int> sorterInt;

int test_array[20];
sorterInt.stuffNum(&test_array, 20, 1, 200);

your template have type int so your method take a int * as argument. And you write &test_array who has type int *[20] because you send the address of your array.

So just remove the &

sorterInt.stuffNum(test_array, 20, 1, 200);

You need a better understanding of pointer.

edit: (read comment)

(*object)[i] = 5;

here you should remove * and () like this

object[i] = 5;

more doc here What is array decaying?