I have a struct which has a unique key. I want to insert instances of these structs into a set. I know that to do this the < operator has to be overloaded so that set can mak
see ereOn's answer, it's right.
The real problem in you code is this:
foo *test = new foo;
test->key = 0;
bar.insert(test);
You insert a pointer in the set, not a struct. Change the insert to:
bar.insert( *test );
// ^
EDIT: but then you'll need to delete foo, as it will be copied in the set. Or just create it on the stack (using set with pointers is not a good idea, because the arrangement will be "strange" - the set will sort according to the pointers' addresses )