![]() |
|
#1
|
|||
|
|||
Building ErrorsHello Everyone! I'm new to GID and relatively new to C++ and was wondering if anyone could help me with a problem i'm having. In the following program im trying to pass arrays using two different methods. I just cant understand the errors im getting and how to correct them. Any help would be appreciated thanks.
CPP / C++ / C Code:
and the errors i am recieving are: Code:
Last edited by LuciWiz : 10-May-2007 at 06:04.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: Building ErrorsQuote:
Two important things arise: 1. You can not pass arrays as arguments to functions, and functions can not return arrays. (You can, however, pass pointers to the elements of the arrays back and forth.) 2. When you use the name of an array by itself (without the brackets []) in the argument of a function call or as the return value of a function it is treated as a pointer whose value is the address of the first element of the array. Therefore, looking at your functions: you need to pass the addresses for the arrays and let the functions operate on the elements. Since you don't actually use the return values of the arrays, why don't you declare them with a "void" return type? If you really want to return the address of the first element of an array, then you can make the function return type a pointer. Like this: CPP / C++ / C Code:
Note that the functions could have been declared and defined like this: CPP / C++ / C Code:
And the results would have been exactly the same for your functions. It may look to you as if this notation means that you are passing arrays, but, and I hate to repeat myself, you can not pass arrays as arguments to functions. You can pass pointers and that is what happens for both notations that I showed. Note that the notation for calling the functions and the contents of the functions would not change if you decide you like the second notation that I showed for the function header. In other words, the program itself would be exactly the same (and the results would be the same). Regards, Dave |
Recent GIDBlog
Flickr uploads of IA pictures by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compile Errors | jdbrine | C++ Forum | 3 | 30-Jun-2006 11:11 |
| Link Errors | jdbrine | C++ Forum | 10 | 18-Jun-2006 14:55 |
| Compile Errors due to Default Parameters | jdbrine | C++ Forum | 1 | 17-Jun-2006 14:45 |
| In Need of Some Serious Help...compiling errors [C++] | needcishelp | C++ Forum | 25 | 21-Dec-2005 01:26 |
| Help with compiler errors | Krandygrl00 | C++ Forum | 3 | 01-Jun-2005 07:45 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The