il contenuto del tuo "set" sono puntatori. Quindi il confronto in set::find viene fatto sul valore numerico del puntatore, non sull'oggetto puntato.
Devi fornire pertanto al "set" un funtore adatto:
ad esempio:
Codice PHP:
//
// Compiled and tested with:
// i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
//
// Compilation command line (zero errors, zero warnings):
// $ g++ -Wall -ansi -pedantic main.cpp
//
#include <iostream>
#include <set>
using namespace std;
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z,
float nx, float ny, float nz, float u, float v)
{
_x = x; _y = y; _z = z;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v;
}
float _x, _y, _z, _nx, _ny, _nz, _u, _v;
bool operator ==(const Vertex& other) const;
bool operator < (const Vertex& other) const;
//static const DWORD FVF;
};
bool Vertex::operator==(const Vertex& other) const{
return this->_nx == other._nx;
}
bool Vertex::operator<(const Vertex& other) const{
return this->_nx < other._nx;
}
namespace ig{
template <typename TClass>
struct SLessPointerFunctor{
bool operator ()(const TClass * v1, const TClass * v2) const{
return *v1 < *v2;
}
};
}
int main ()
{
set <Vertex *, ig::SLessPointerFunctor <Vertex> > myset;
// set some initial values:
// Vertex vz,vy;
Vertex* v = new Vertex();
Vertex* v1 = new Vertex();
v->_nx =1;
v1->_nx =1;
myset.insert(v);
if(*v==*v1)
cout<<" uguale";
else
cout<<" diverso";
if(myset.find(v1)== myset.end())
cout<<" non presente";
else
cout<<" gia presente";
int r;
cin >> r;
return 0;
}
osserva che le due parentesi acute prima di myset DEVONO essere separate da uno spazio, altrimenti vengono interpretate come operatore di shift.
Il funtore ig::SLessPointerFunctor come vedi è generico, e probabilmente è già presente nella libreria std in zona std::less, ma non ho voglia di cercarlo ;-)
EDIT: generalizzando ancor di più:
Codice PHP:
#include <functional>
...
namespace ig{
template <typename TBinaryPredicate, typename TClass>
struct SPointerFunctor{
bool operator ()( const TClass * v1, const TClass * v2) const{
TBinaryPredicate a;
return a (*v1, *v2);
}
};
}
...
set <Vertex *, ig::SPointerFunctor <less <Vertex>, Vertex> > myset;