1

How can I overload operator + between two pointers pointing to a new class object ? e.g

class A{

}

A* operator+(A* p1,A*p2){
   return A;
}

I'm using objects only with pointers so I need to use pointers.

Winter
  • 3,591
  • 7
  • 23
  • 51
Theredone
  • 55
  • 6

1 Answers1

1

How can i overload operator + between two pointers?

The standard doesn't allow for both parameters to the operator+ to be pointers:

§[expr.add]/1 For addition, either both operands shall have arithmetic or unscoped enumeration type, or one operand shall be a pointer to a completely-defined object type and the other shall have integral or unscoped enumeration type.

wally
  • 10,227
  • 4
  • 36
  • 69