I'm fairly new to C++ and I recently came across this problem.
This code will obviously work:
void setvalues(int *c, int *d)
{
(*c) = 1;
(*d) = 2;
}
int main()
{
int a, b;
setvalues(&a, &b);
std::cout << a << b;
}
So why does this return an error? Visual C++ 2010 error:
C2664: 'setvalues' : cannot convert parameter 1 from 'int (*)[2]' to 'int *[]'
void setvalues(int *c[2], int *d[2])
{
(*c[1]) = 1;
(*d[1]) = 2;
}
int main()
{
int a[2], b[2];
setvalues(&a, &b);
std::cout << a[1] << b[1];
}
What's different about pointers to arrays? I searched around but no luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With