Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# declaring multi-dim array in functions?

Posted on 1998-12-09
Medium Priority
203 Views
I need to use a 2-dim array in the arguments of a construct
like this....

{
....
m_F = array[i][j];
....

}

but when i make a call to the construct, like this...
........
double values_x[3][3];
........
it tell me that cannot convert parameter 3 from 'double [3][3]' to 'const double **
anybody can tell me what the error? and how to solve it

....
MG
0
Question by:mguedes
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 3

LVL 6

Expert Comment

ID: 1179718
Did you try to cast the argument :

0

Author Comment

ID: 1179719
Yes, but when i try to use the array in the construct i receive an error because it can´t reference it(tell´me that the array is NULL)
0

LVL 6

Accepted Solution

stsanz earned 20 total points
ID: 1179720
the parameter type is wrong. The array parameter is not equivalent to a "const double **", but to a "const double*"

Because you have a 2-dimentional array, the compiler must know at least the size of the first dimension. Declare your function this way :

{
..
m_F = array[i][j];
..

}

Now you can access it by :
double values_x[3][3];

0

LVL 6

Expert Comment

ID: 1179721
If you have to call CMask::CMask with various size arrays, and can't pass the size as a litteral, use the following form :

{

//m_F = array[x][y];
m_F = *(array + x * y_size + y) ;

}

and use it with :

Hope this helps.

0

Author Comment

ID: 1179722
it´s not resolve my problem because i need a 2-dim array with variable dimensions.............but thank´s anyway.....if you know how to solve my problem.....tell me :o)
0

Author Comment

ID: 1179723
ok, i have solve the problem.....with your suggestion, thank´s
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
###### Suggested Courses
Course of the Month11 days, 8 hours left to enroll