Original Post
Hi.
I am just wondering how to quickly compare two objects if they are equal or not. eg.
if( object1 == object2 ) return true;
I know I can add == comparison operator in my class: eg.
class Object {
int m_id;
public:
bool operator== (const Object & obj)
{
if (m_id == obj.m_id)
{
return TRUE;
}
}
but then what do I do if I have a huge object with many members that store list of pointers and other objects or list of vertices storing 3000 vertices?
I dont thik it would be wise to comapre each member (eg. vertex list vertex-by-vertex)in the Object class to determine if the two objects Obj1 and Obj2 are equal. It would take ages!!
Is there any clever way of doing it.
My problem is that I have a global list of Objects stored in vector container.
vector<objects*>vlist;
I select an object randomly from the list of objects and I pass that object to some other function. eg.
How can I compare those objects fast?
[edited by - robert_s on June 10, 2004 12:22:12 PM]
// 'loc_obj' is pointing at one of those objects in 'vlist' but I dont know at this point which object this is. I mean I dont know which index in the list it is.
bool ObjFound( Object *loc_obj)
{
for( loop through vlist of objects to the end)
{
// see if loc_obj is one of those in the list
if( vlist[i] == loc_obj )return true;
}
}
I know the code is meaningless but its just a quick problem illustration