Reputation: 4885
Is it possible to do operator overloading or something similar (inline function?) in C? I know that c does not support class
, but could I make an operator for a struct
?
I cannot find anything about this online, because Google will ignore '+' so if I try to google this I only get C++ results.
Upvotes: 3
Views: 5975
Reputation: 28144
C++ introduced an important and interesting feature which is operator overloading.
So you will have to use it if you want to use this feature.
Upvotes: 1
Reputation: 59238
No it is not possible.
By the way, you can remove C++
from google search results if you add -"C++"
to your search query.
Upvotes: 6
Reputation: 3165
C does not support operator overloading or having functions inside structs. You will need to use C++ for those features.
Upvotes: 0
Reputation: 225032
No, you can't do that in C. Use C++ if you want to overload operators.
You can put function pointers inside a structure if you want a sort of C++ object-like behaviour.
Upvotes: 9