Solved

declaring multi-dim array in functions?

Posted on 1998-12-09
6
195 Views
Last Modified: 2010-04-02
I need to use a 2-dim array in the arguments of a construct
like this....

CMask::CMask(BYTE x, BYTE y, const double** array)
{
....
    m_F = array[i][j];
....

}

but when i make a call to the construct, like this...
........
double values_x[3][3];
CMask* masc_x = new CMask(3, 3, values_x);
........
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

....
thank´s in advance,
MG
0
Comment
Question by:mguedes
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:stsanz
ID: 1179718
Did you try to cast the argument :
CMask* masc_x = new CMask(3, 3, (const double**)values_x);

0
 

Author Comment

by:mguedes
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

by:
stsanz earned 10 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 :

CMask::CMask(BYTE x, BYTE y, double array[][3])
{
..
    m_F = array[i][j];
..

}

Now you can access it by :
double values_x[3][3];
CMask* masc_x = new CMask(3, 3, values_x);

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:stsanz
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 :

CMask::CMask(BYTE x, BYTE y, const double *array, int y_size)
{
 
    //m_F = array[x][y];
    m_F = *(array + x * y_size + y) ;
 

}

and use it with :
CMask* masc_x = new CMask(3, 3, (const double*)values_x,3);

Hope this helps.

0
 

Author Comment

by:mguedes
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

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Focus not getting shifted out of  editbox 2 66
is twain_32.dll cmpatible with windows 10 ? 10 186
VS2015 Redefinition errors 4 70
Finding Divisors 5 19
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question