In C++, I can change the operator on a specific class by doing something like this:
MyClass::operator==/*Or some other operator such as =, >, etc.*/(Const MyClass rhs) {
/* Do Stuff*/;
}
But with there being no classes (built in by default) in C. So, how could I do operator overloading for just general functions?
For example, if I remember correctly, importing stdlib.h gives you the -> operator, which is just syntactic sugar for (*strcut_name).struct_element.
So how can I do this in C?
Thank you.
Plain old C does not have operator overloading in any form. The ->
"operator" to access a member of a pointer is standard C and is not introduced by any header file.
Built-in operators in C language are overloaded. The fact that you can use binary +
to sum integers, floating-point numbers and perform pointer arithmetic is a canonical example of operator overloading.
However, C offers no features for user-level operator overloading. You can't define your own operators in C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With