I have a class. I have made two seperate files, the header, and the c++ file. I am using it to create a more-or-less Light ‘object’ for an opengl game I am working on. Here are the files:
Light.h
#ifndef LIGHT_H
#define LIGHT_H
class Light
{
public:
Light(float ix, float iy, float iz, float ir, float ig, float ib , float ia, int itype, int iindex);
virtual ~Light();
float x,y,z;
int index;
int type;
struct ambient
{
float r, g, b, a;
};
struct diffuse
{
float r, g, b, a;
};
struct specular
{
float r, g, b, a;
};
protected:
private:
};
#endif // LIGHT_H
and, Light.cpp
#include "../include/Light.h"
Light::Light(float ix, float iy, float iz, float ir, float ig, float ib , float ia, int itype, int iindex)
{
index=iindex;
type=itype;
x=ix;
y=iy;
z=iz;
ambient.r = 0.2;
ambient.g = 0.2;
ambient.b = 0.2;
ambient.a = 1.0;
specular.r = 0.8;
specular.g = 0.8;
specular.b = 0.8;
specular.a = 1.0;
diffuse.r = ir;
diffuse.g = ig;
diffuse.b = ib;
diffuse.a = ia;
}
Light::~Light()
{
//dtor
}
When I try to compile, it throws an error saying:
error: expected unqualified-id before ‘.’ token|
For every line where I assign a value to a member of the structs (ambient, diffuse, specular)
First off, I can’t even interpret this error. No clue what it means. Secondly, I fail to see what I am doing wrong. Please help!
This should read so:
The basic problem is that you were declaring that the structs existed and giving the name of the type, but you weren’t declaring any variables of that type. Since, from your usage, it was clear that the type of these structs didn’t need a name (they could be anonymous structs) I moved the name after the declaration so you were declaring a variable instead.
As GMan pointed out, this is still not optimal. Here is a better way to go about this: