473,388 Members | 1,277 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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

Sep 19 '06 #1
5 1940
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stefan J. Galler | last post by:
Hi vielleicht kann mir ja jemand helfen! Ich brauch ein 3D-Array. Die Klasse heißt Vector3D und hat eine Membervariable: private: int ***field_; im Konstruktor initialisiere ich dann diese...
8
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
6
by: Spikey | last post by:
Hi, I have a problem that's (probably) very easy to solve, only I'am more a Java programmer and I couldn't find anything like it on the internet. My problem is that I have to add a variable (int,...
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.