Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

How to pass a dyn. multi-D array to func.

Name: Axen 2006-06-18 12:35

I'm probablly just getting the syntax wrong.  Here's what I got.

// function declaration
void process_mat (int nMat, char matName[][25]);

// multidimensional dynamic array initialization
char **matName;
matName = new char*[nMaterials];
for (int i=0; i < nMaterials; i++)
   matName[i] = new char[25];

//function call
process_mat(nMaterials, matName);

When I try to compile, the error I get is "cannot convert type 'char**' to type 'char(*)[25]'"

Name: Anonymous 2006-06-18 13:05

void process_mat (int nMat, char** matName);

Name: Anonymous 2007-11-27 16:17

lol
  noobs

lol
noobs

lol
noobs

lol
noobs

Name: Anonymous 2007-11-27 16:18

lol
 noobs

Name: Anonymous 2007-11-27 16:22

lol <
noobs

Name: Anonymous 2007-11-27 16:31

[quote]lol
noobs[/quote]

Name: Anonymous 2008-02-20 19:23

what we have here is a classic example of bbcodepointerexception

Name: Anonymous 2008-02-20 19:42

HAY GUYS HOW DO I POINTER

Name: Anonymous 2008-02-20 19:43

OH fuck i'll help him. avoid using [] in function definitions. just use *'s.  C treats them the same but it saves getting confused.

Name: Anonymous 2008-02-20 20:06

There is no such thing as a multidimensional array. C++ only has arrays of arrays, i.e. arrays whose elements are other arrays. char **matName is not an array, it's a pointer to pointer to char. If you want to pass it to a function, make it take a char **.
char matName[][25] (bbcode failure?) is a declaration of an array (of unknown size) of an array (of size 25) of char. Strictly speaking this should be invalid, since this is a function parameter, function arguments are passed by value, and there are no array values. However, a function parameter declared as array [N] of type T is silently adjusted to pointer to T; any size information is ignored. In other words, the compiler just pretends you've written char (*matName)[25] (that's a pointer to an array [25] of char).
This is also what the error message says: a pointer to pointer to char is not compatible with a pointer to an array [25] of char.

Name: Anonymous 2008-02-21 3:30

>>10
Quite accurate.

Name: Anonymous 2008-02-21 5:15

>>11
Quite trolling

Name: Anonymous 2009-03-06 11:57


With Sting I read about RSA and   there was a   great experience and   went KTHXBAI Paying.

Name: Sgt.Kabu啿kiman㑙㒂 2012-05-28 19:11

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List