PDA

View Full Version : Not an OpenGL question!



McZ
12-20-2000, 12:58 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif
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.

Eric
12-20-2000, 01:11 AM
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

DPalomo
12-20-2000, 01:13 AM
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) &amp;&amp; (y == arg.y) &amp;&amp; (z == arg.z));}


Hope this helps,

Daniel.

McZ
12-20-2000, 01:23 AM
thanks alot for your help ! http://www.opengl.org/discussion_boards/ubb/smile.gif I hope this will solve my problems http://www.opengl.org/discussion_boards/ubb/smile.gif and I will survive X-mas! http://www.opengl.org/discussion_boards/ubb/smile.gif happy X-Mas to you http://www.opengl.org/discussion_boards/ubb/smile.gif