I’m completely new to C++.
Bashing my head against this error for over an hour. Probably someone with experience can see right through it.
The following code gives an error:
class TimeTravellingCellar {
private:
public:
int determineProfit (int [] profit, int [] decay) {
int N = sizeof(profit)/sizeof(decay);
int max = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j) continue;
if (profit [i] - decay [j] > max)
max = profit [i] - decay [j];
}
}
return max;
}
}
Visual Studio Express puts a red line under profit in the parameters of determineProfit and says:
expected a ')' before identifier profit.
I will appreciate some help.
Thanks!
You don’t declare arrays like that in C++, the
[]needs to go after the name.Also note you need to have a semicolon after the class declaration.
Edit: also remember that sizeof(pointer) will return the number of bytes of the pointer type, not the number of elements in the array. So if you have an
intarray,sizeof(array) == sizeof(int). YourNvalue will always equal 1.