Jump to content
  • Advertisement
Sign in to follow this  
NcatDesigner

OOP returning arrays (or reference it)

This topic is 4252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello people! Alert! This is a newbie question XD I've got a class called Cube and one of its parameters is _glColor[4] an array of four floats My question is, how can I implement the methods _something_ getColor() {}; setColor(_something_); please help me thank you for read this and sorry for my bad writting!

Share this post


Link to post
Share on other sites
Advertisement
I suggest you just use a struct for this:

struct RGBA
{
float r,g,b,a;
};

It makes more sense than an array in this case and is more practical. You can access each channel with, say, "color.g" and not "color[1]". Then, you can implement Get/SetColor:

RGBA getColor() const
{
return m_color;
}

void setColor(const RGBA& color)
{
m_color=color;
}

Share this post


Link to post
Share on other sites
Something it's wrong getting the color.

Setting it works perfectly.


protected:
struct RGBA {
float r,g,b,a;
};
RGBA _Color;

void setColor(const RGBA&);
RGBA getColor() const;




void gl3DPrimitive::setColor(const RGBA& color)
{
_Color.r = color.r;
_Color.g = color.g;
_Color.b = color.b;
_Color.a = color.a;
}

RGBA gl3DPrimitive::getColor() const
{
return _Color;
}

I'm using visual c++, any idea??



Error 1 error C2143: syntax error : missing ';' before 'gl3DPrimitive::getColor' d:\Documents and Settings\BOSS\Mis documentos\Apocalypse\Apocalypse\gl3DPrimitive.cpp 36

Share this post


Link to post
Share on other sites

RGBA gl3DPrimitive::getColor() const
{
return _Color;
}


should be:

gl3DPrimitive::RGBA gl3DPrimitive::getColor() const
{
return _Color;
}


But you're better off making RGBA seperate from gl3DPrimitive. The way it stands right now, not much will be able to use it, as it's declared as being protected.


Also, as an aside, names begining with an underscore followed by an uppercase letter are reserved for the implementation (i.e. the compiler and the standard library).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!