| View previous topic :: View next topic |
| Author |
Message |
Thomas Kowalski Guest
|
Posted: Tue Sep 19, 2006 9:10 am Post subject: Passing array to methode |
|
|
Hi everyone,
recently I have trouble to pass an array (unsigned char color[3]) to a
methode by reference and collect the return value by reference.
I wanted something like:
unsigned char[3]& changeColor(unsigned char[3]& color);
How would the correct syntax look like?
Thanks in advance,
Thomas Kowalski |
|
| Back to top |
|
 |
Stuart Redmann Guest
|
Posted: Tue Sep 19, 2006 9:10 am Post subject: Re: Passing array to methode |
|
|
Thomas Kowalski wrote:
| Quote: | Hi everyone,
recently I have trouble to pass an array (unsigned char color[3]) to a
methode by reference and collect the return value by reference.
I wanted something like:
unsigned char[3]& changeColor(unsigned char[3]& color);
How would the correct syntax look like?
|
I suppose that this is a point where you can get around a typedef.
typedef unsigned char CharArray[3];
CharArray& changeColor (CharArray& p_Color)
{
return p_Color;
}
Regards,
Stuart |
|
| Back to top |
|
 |
Stefan Naewe Guest
|
Posted: Tue Sep 19, 2006 9:10 am Post subject: Re: Passing array to methode |
|
|
Thomas Kowalski schrieb:
| Quote: | Hi everyone,
recently I have trouble to pass an array (unsigned char color[3]) to a
methode by reference and collect the return value by reference.
I wanted something like:
unsigned char[3]& changeColor(unsigned char[3]& color);
|
If you pass the array to the function by reference, why
do you wnat to return it as a reference as well ?
| Quote: | How would the correct syntax look like?
|
I'd use a typedef:
typedef unsigned char Color[3];
Color& changeColor(Color & col)
{
return col;
}
int main()
{
Color c;
Color& b = changeColor(c);
return 0;
}
But I really don't understand what you want to achieve with this.
S.
--
Stefan Naewe
stefan_DOT_naewe_AT_atlas_DOT_de |
|
| Back to top |
|
 |
Thomas Kowalski Guest
|
Posted: Tue Sep 19, 2006 9:10 am Post subject: Re: Passing array to methode |
|
|
| Quote: | typedef unsigned char Color[3];
|
If you see it, it's quite simple (hit my head). Thanks
| Quote: | But I really don't understand what you want to achieve with this.
Actually I mixed two different methodes. |
I have a getter and and change methode but I combined them to keep the
text short.
Thanks,
Thomas Kowalski |
|
| Back to top |
|
 |
|