Is there any way to overload the > (greater than) operator, to be able to do something like:
myClass *a = new myClass(1);
myClass *b = new myClass(3);
if(a > b) //it should compare the int values from the constructors
//do something
I’ve tried overloading the operator, but got various errors. I am using VC++.
You cannot overload operators for pointers, because they are primitive types (and you cannot create an overload where both arguments are primitive types); instead, you can overload the operators for your objects of user-defined types (not pointer to them):
notice that, if you don’t have a particular reason to allocate stuff on the heap, it’s much better to just allocate it on the stack: