Operator datatype

hi there,
im just wondering is there any data type for operator [+,-,x,/] ??
because i trying to reduce my code as following:
1
2
3
Calculate(int x, int y, operator z){
 return (x z y);
};


if z= '+', then return value will be x+y.
It is better rite?
if got such data type pls let me know =)
operators are member functions. You can't do that, though what you want to do could be realized by passing a functor (an object with a () operator), a function pointer (a pointer to a function, duh) or a member function pointer (a pointer to a member function. Note that you also need to have an instance of the class that provides the function (or just the class itself if it's static) to use member function pointers.

Note that you also need a return value for that.

PS: Templates are also an option.
Topic archived. No new replies allowed.