Pointers and Arrays - MS 2010

All questions regarding Windows programming, post here. API,COM, ActiveX, DirectX, OpenGL, MFC and so on...

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Pointers and Arrays - MS 2010

Postby Gandalph » Thu Mar 15, 2012 5:14 am

Greetings.
I am trying (and failing miserably :cry: ) to set up a pointer to a two dimensional array of floats or doubles. I can set up the array and acces it quite sucessfully, but to pass the array to a function I need a pointer (other than the original array name).
Every time I try what appears a logical declaration (utilising * and &) I get an error message of the form "A value of type "float(*)[3][3]" cannot be assignet to an entity of type "float*

I am using Microsoft Visual Studio 2010 and developing a programme for Windows.

Help please before any more hair hits the floor !

Thanks in anticipation of your help
Gandalph.
"I have yet to see any problem, however complicated, which
when looked at in the right way, did not become still more complicated"
Poul Anderson
Gandalph
 
Posts: 11
Joined: Tue Mar 06, 2012 7:10 am

Re: Pointers and Arrays - MS 2010

Postby exomo » Fri Mar 16, 2012 2:20 am

Pointers to multidimensional arrays are a little confusing.
You might want to look at http://www.eskimo.com/~scs/cclass/int/sx9a.html they explain quite good how you can pass multidimensional arrays.
Basically if you want a pointer to your array it looks like this:
Code: Select all
float arr[3][3] = { {1,2,3},{4,5,6}, {7,8,9}};
    float (*a)[3] = arr;


The best way to use multidimensional arrays is to not use them :D If possible use std::vector. Or you can use a single dimension array of size m*n (when m and n are the sizes od your two array dimensions).
Who needs a signature anyway.
User avatar
exomo
 
Posts: 881
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Re: Pointers and Arrays - MS 2010

Postby Gandalph » Fri Mar 16, 2012 7:02 am

Greetings from the UK.

Many thanks for your help - problem solved and hair remaining in head !! :D
The web referance you gave as also a good site for the exlpanation of this area.

Gandalph.
"I have yet to see any problem, however complicated, which
when looked at in the right way, did not become still more complicated"
Poul Anderson
Gandalph
 
Posts: 11
Joined: Tue Mar 06, 2012 7:10 am


Return to Windows Programming

Who is online

Users browsing this forum: No registered users and 1 guest