Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multidimension array as function parameter

Status
Not open for further replies.

qzou666

Programmer
Feb 12, 2002
11
0
0
NZ
Hi,

I have a c++ programme as follow:

void AFunction(float** p){ .....};

float p1[4][4]={{1.0f,0.7407f,0.2593f,0.0f},
{0.0f, 0.2593f, 0.7407f, 1.0f},
{0.0f, 0.1481f, 0.0741f, 0.0f},
{0.0f,-0.0741f,-0.1481f,0.0f}};

AFunction(p1);

When I compile, I was told:

cannot convert parameter 1 from 'float [4][4]' to 'float ** '

Would anyone explain why.

Thanks a lot

Qian
 
the type of p1 is float *. you should call it as
AFunction(&p1);

or change the definition of AFunction as:
AFunction(float *)
 
Thank you very much, Jeffray.

I tried your suggestion

(1)for 'call it as AFunction(&p1)'

The compiler tell me

cannot convert parameter 1 from 'float (*)[4][4]' to 'float ** '

(2)for 'change the definition of AFunction as:
AFunction(float *)'

I have to use expression such as p[3][3] in the function, the float * seems not work.

Can you think of any thing else to solve my problem.

Cheers
 
void AFunction(float p[4][4]){ .....};

will do the job if it's ok with you to always receive a 4 by 4 array...

hope this will help...
 
Thank you, BobbyB.

Your suggestion works when I ony use the array with fixed index range.

However, I need to use the arrays with different index ranges as the function parameter.

Can you think of any other answer to this situation.

Cheers.
 
void AFunction( float p[][4]){ .....};
This should work !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top