I'm trying to recursively call a function with a 2d array as an argument.
My compile error is
knapsack.cpp:76:55: error: cannot convert ‘int (*)[(((sizetype)(((ssizetype)(knapsack_capacity + 1)) + -1)) + 1)]’ to ‘int**’ for argument ‘1’ to ‘void backtrack(int**, int, int, std::vector)’ backtrack(T, items_amount, knapsack_capacity, weights);
My function is declared like this:
void backtrack (int **T, int item, int weight, vector<int> weights)
{
if (T[item][weight] == T[item-1][weight]) {
cout << item << ", ";
backtrack(T, item-1, weight-weights[item-1], weights);
}
else if (item <= 0 && weight <= 0) {
// Dont do anything
}
else {
backtrack(T, item-1, weight, weights);
}
}
And being called like this:
backtrack(T, items_amount, knapsack_capacity, weights);
I looked in a million different ways of combining [] and *, but no success. Any ideas?