ti posto il codice,non riesco a farlo funzionare:
if(*v==*v1)codice:#include "stdafx.h" #include <iostream> #include <set> #include "struct2s.h" using namespace std; int main () { set<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; } 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 ==(Vertex& other); //static const DWORD FVF; }; bool Vertex::operator==(Vertex& other) { if(this->_nx == other._nx) return true; return false; }
entra nell overload ritorna true ed è giusto , ma..
if(myset.find(v1)== myset.end())
cout<<" non presente";
else
cout<<" gia presente";
int r;
non entra nella funzione di overload,ritorna true e non dovrebbe , mi aspetterei un false in quanto è già presente un oggetto con le stesse caratteristiche:
v->_nx =1;
v1->_nx =1;
myset.insert(v);//inserito
ciao.

Rispondi quotando