Search code examples
coperator-overloading

Operator overloading in C


I am trying to overload some operators:

/* Typedef is required for operators */
typedef int Colour;

/* Operators */
Colour operator+(Colour colour1, Colour colour2);
Colour operator-(Colour colour1, Colour colour2);
Colour operator*(Colour colour1, Colour colour2);
Colour operator/(Colour colour1, Colour colour2);

I get this error for each tried overloading:

expected '=', ',', ';', 'asm' or '__attribute__' before '+' token

I can't find any good documentation on operator overloading. Googling results in C++ tutorials which use classes. In C there are no classes. Can anyone help me? Thanks.


Solution

  • C does not support operator overloading (beyond what it built into the language).