C++ increment ++ operator overloading -
i know how overload operator += if using class e.g.
class temp { public: int i; temp(){ = 10; } int operator+=(int k) { return i+=k; } }; int main() { temp var; var += 67; cout << var.i; return 0; }
but why cant create overloaded += function basic datatype
int operator+=(int v, int h) { return v += (2*h); } int main() { int var = 10; var += 67; cout << i; return 0; }
i getting error when compiling above overloaded function.
operator overloading not supported primitive types. these operations performed direct cpu instructions. reason though, code overloads basic arithmetic functions impossible maintain.
Comments
Post a Comment