> And what is this supposed to do? ^^
> operator* has no body. And I guess vector<Ptr<int> > is supposed to be
> vector<DerefPtr<int> > ?
>
Sorry for the confusion.
#include "stdafx.h"
#include <vector>
#include <functional>
#include <algorithm>
#include <iterator>
using namespace std;
// Comparison functor for use with associative containers
struct DereferenceLess {
public:
template<typename PtrType> bool operator()(PtrType pT1, PtrType pT2)
{
return *pT1 < *pT2;
}
};
struct Dereference {
template<typename T> const T& operator()(const T* ptr) const
{
return *ptr;
}
};
int main(int argc, char *argv[])
{
int *pi3 = new int(

;
int *pi = new int(10);
int *pi2 = new int(9);
int *pi4 = new int(7);
vector<int* > vec;
vec.push_back(pi);
vec.push_back(pi2);
vec.push_back(pi3);
vec.push_back(pi4);
sort(vec.begin(), vec.end(), DereferenceLess());
transform(vec.begin(), vec.end(), ostream_iterator<int>(cout, "\n"),
Dereference() );
set<int *, DereferenceLess> s;
s.insert(pi1);
s.insert(pi2);
s.insert(pi3);
s.insert(pi4);
transform(vec.begin(), vec.end(), ostream_iterator<int>(cout, "\n"),
Dereference() );
return 0;
}