Not an OpenGL question!

please help me someone ! I´m going crazy or something…

I have created som classes and I got a error that I have look and read about for about 1000 times or somthing but I can´t understand how I would fix it. I hope anyone of you could explain to me how I could do it
to the problem:

this are my classes:
struct OGL_Vertex {
GLfloat x;
GLfloat y;
GLfloat z;
};

class OGL_Object {
int NrVertices;
OGL_Vertex Vertices[50];
void AddTriangle(OGL_Vertex v1, OGL_Vertex v2, OGL_Vertex v3);
};

this is my addtriangle function:
void OGL_Object::AddTriangle(OGL_Vertex v1, OGL_Vertex v2, OGL_Vertex v3)
{
/* some other code */
for (i=0; i<NrVertices; i++)
{
if(Vertices[i] == v1) <— there is the error
{
do something
}
}

the error I get is somthing like this: left-hand operation not allowed.

I don´t remember exact and I am not at home so I can´t check! but I hope someone understans and can help me with this.

You should modify your OGL_Vertex as follows:

struct OGL_Vertex
{

GLfloat x;
GLfloat y;
GLfloat z;

bool operator==(C_OGL_Vertex& Vertex);

}

Then:

bool OGL_Vertex::operator==(C_OGL_Vertex& Vertex)
{

return((X==Vertex.X)&&(Y==Vertex.Y)&&(Z==Vertex.Z));

}

What happens here is that you create a new object and ask the compiler to compare them… The problem is that the compiler hasn’t got a clue on what to compare… You need to tell it that two of your objects are equal if and only if their members are equal…

Regards.

Eric

Originally posted by McZ:
[b]
this are my classes:
struct OGL_Vertex {
GLfloat x;
GLfloat y;
GLfloat z;
};

class OGL_Object {
int NrVertices;
OGL_Vertex Vertices[50];
void AddTriangle(OGL_Vertex v1, OGL_Vertex v2, OGL_Vertex v3);
};

this is my addtriangle function:
void OGL_Object::AddTriangle(OGL_Vertex v1, OGL_Vertex v2, OGL_Vertex v3)
{
/* some other code */
for (i=0; i<NrVertices; i++)
{
if(Vertices[i] == v1) <— there is the error
{
do something
}
}

left-hand operation not allowed.

You are trying to use a ‘==’ operator on a structure. The bad ting is that there is no operation ‘==’ defined for that structure, OGL_Vertex. You could try to define the ‘==’ operator.

I suppose that Vertices[i] the same type has as v1.

It should look something, like:

bool operator== (const OGL_Vertex arg) {return ((x == arg.x) && (y == arg.y) && (z == arg.z));}

Hope this helps,

Daniel.

thanks alot for your help ! I hope this will solve my problems and I will survive X-mas! happy X-Mas to you