C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing array to methode

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Thomas Kowalski
Guest





PostPosted: Tue Sep 19, 2006 9:10 am    Post subject: Passing array to methode Reply with 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?

Thanks in advance,
Thomas Kowalski
Back to top
Stuart Redmann
Guest





PostPosted: Tue Sep 19, 2006 9:10 am    Post subject: Re: Passing array to methode Reply with quote



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





PostPosted: Tue Sep 19, 2006 9:10 am    Post subject: Re: Passing array to methode Reply with quote



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





PostPosted: Tue Sep 19, 2006 9:10 am    Post subject: Re: Passing array to methode Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.