Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function overloading

Tags:

c++

I found this code , and i m not sure that whether overloading should happen or not.

void print( int (*arr)[6], int size );

void print( int (*arr)[5], int size );

what happens if I pass pointer to an array of 4 elements , to it should come...

any thread will be helpful.

like image 704
user310712 Avatar asked Dec 04 '22 13:12

user310712


1 Answers

Overloading will happen, and passing the pointer to the array of 4 int's will not match either function. It's clearer if you write them as the equivalent form:

void print( int arr[][6], int size );
void print( int arr[][5], int size );

An N×4 array can be decayed to a pointer to array of 4 int's. And it's well known that 2D arrays having different 2nd dimensions are incompatible.

like image 112
kennytm Avatar answered Dec 27 '22 07:12

kennytm