nubira
11-03-2005, 03:49 PM
Hi all
Sorry if this seems very simple and obvious to you. I would appreciate it a lot if you could help me and describe how to do this properly.
I am trying to figure out how to return an unsigned char array from a class method. The class is just a practice how to store RGB color values as an object. I chose unsigned char for the type because it is enough to represent RGB values from 0 to 255.
The header file of the class looks like this:
#ifndef _CARRAYRGB_H_
#define _CARRAYRGB_H_
class CArrayRGB
{
private:
unsigned char values[3];
public:
CArrayRGB();
CArrayRGB( unsigned char R, unsigned char G, unsigned char B );
~CArrayRGB() {}
void setColor( unsigned char R, unsigned char G, unsigned char B );
unsigned char* getColor();
};
#endif
The class method file looks like this:
#include "CArrayRGB.h"
CArrayRGB::CArrayRGB()
{
values[0] = 255;
values[1] = 255;
values[2] = 255;
}
CArrayRGB::CArrayRGB( unsigned char R, unsigned char G, unsigned char B )
{
values[0] = R;
values[1] = G;
values[2] = B;
}
void CArrayRGB::setColor( unsigned char R, unsigned char G, unsigned char B )
{
values[0] = R;
values[1] = G;
values[2] = B;
}
unsigned char* CArrayRGB::getColor()
{
return values;
}
...and in the client file I have this (well actually it's quite empty):
//blah blah, then include class header:
#include "CArrayRGB.h"
// blah blah, then:
CArrayRGB rgbarr; // create object which holds RGB
// BEEP! What do I do here to get the RGB in form 255,255,255
// which I can then pass to whatever needs the RGB values...?
// using rgbarr.getColor(); somehow but, how?
// blah, blah, program end.
As you can see this is very basic but still, I can't figure it out myself. I am guessing my class header file and method file are not quite right... And because they are not right, I can't continue to write the client file because I have no clue how to get the RGB values from the object in form 255,255,255 so that I can pass them to whatever needs them.
Corrections, improvements, suggestions etc. are very, very welcome.
Thanks in advance for guiding me through what I did wrong and how to do it properly.
Sorry if this seems very simple and obvious to you. I would appreciate it a lot if you could help me and describe how to do this properly.
I am trying to figure out how to return an unsigned char array from a class method. The class is just a practice how to store RGB color values as an object. I chose unsigned char for the type because it is enough to represent RGB values from 0 to 255.
The header file of the class looks like this:
#ifndef _CARRAYRGB_H_
#define _CARRAYRGB_H_
class CArrayRGB
{
private:
unsigned char values[3];
public:
CArrayRGB();
CArrayRGB( unsigned char R, unsigned char G, unsigned char B );
~CArrayRGB() {}
void setColor( unsigned char R, unsigned char G, unsigned char B );
unsigned char* getColor();
};
#endif
The class method file looks like this:
#include "CArrayRGB.h"
CArrayRGB::CArrayRGB()
{
values[0] = 255;
values[1] = 255;
values[2] = 255;
}
CArrayRGB::CArrayRGB( unsigned char R, unsigned char G, unsigned char B )
{
values[0] = R;
values[1] = G;
values[2] = B;
}
void CArrayRGB::setColor( unsigned char R, unsigned char G, unsigned char B )
{
values[0] = R;
values[1] = G;
values[2] = B;
}
unsigned char* CArrayRGB::getColor()
{
return values;
}
...and in the client file I have this (well actually it's quite empty):
//blah blah, then include class header:
#include "CArrayRGB.h"
// blah blah, then:
CArrayRGB rgbarr; // create object which holds RGB
// BEEP! What do I do here to get the RGB in form 255,255,255
// which I can then pass to whatever needs the RGB values...?
// using rgbarr.getColor(); somehow but, how?
// blah, blah, program end.
As you can see this is very basic but still, I can't figure it out myself. I am guessing my class header file and method file are not quite right... And because they are not right, I can't continue to write the client file because I have no clue how to get the RGB values from the object in form 255,255,255 so that I can pass them to whatever needs them.
Corrections, improvements, suggestions etc. are very, very welcome.
Thanks in advance for guiding me through what I did wrong and how to do it properly.