struct GLColor
{
GLfloat r;
GLfloat g;
GLfloat b;
GLColor():r(0),g(0),b(0){}//默认构造函数
GLColor(GLfloat rValue,GLfloat gValue,GLfloat bValue)//构造函数
:r(rValue),g(gValue),b(bValue){}
GLColor(const GLColor& srcColor)//复制构造函数
{
*this = srcColor;
}
GLColor& operator=(const GLColor& srcColor)//重载运算符=
{
r = srcColor.r;
g = srcColor.g;
b = srcColor.b;
return *this;
}
void SetValue(GLfloat rValue=0,GLfloat gValue=0,GLfloat bValue=0)//结构体函数
{
r = rValue;
g = gValue;
b = bValue;
}
};
注意赋值构造函数与重载运算符=中的const关键字,一定要有。
无论函数体中是否有代码,函数的{}后不需要;
本文详细介绍了GLColor结构体的设计与实现,包括其构造函数、复制构造函数、重载运算符=以及SetValue方法等核心成员函数。通过这些内容,读者可以了解到如何在OpenGL程序中使用GLColor来设置颜色。
2439

被折叠的 条评论
为什么被折叠?



