By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,040 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,040 IT Pros & Developers. It's quick & easy.

Passing array to methode

P: n/a
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

Sep 19 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Thomas Kowalski wrote:
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
Sep 19 '06 #2

P: n/a
Thomas Kowalski schrieb:
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 ?
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
Sep 19 '06 #3

P: n/a
typedef unsigned char Color[3];

If you see it, it's quite simple (hit my head). Thanks
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

Sep 19 '06 #4

P: n/a
Thomas Kowalski wrote:
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);
unsigned char (& changeColor( unsigned char ( & color )[3] ) )[3]
{
return foo;
}
>
How would the correct syntax look like?
The typedef answers are better but if you need to create a template,
you're likely going to need to use that syntax.
Sep 19 '06 #5

P: n/a

Thomas Kowalski wrote:
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?
struct color {
unsigned char components[3];
color& changeColor(); // return *this after modification.
};

And the free function:
color& changeColor(color& c); // returns c

HTH,
Michiel

Sep 19 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.