c++ - Operator- overloading (same parameters, different return type) -


how overload minus operator accepting same number of parameters, having different return types?

template class:

template <typename t> t minus (t x, t y) {     return (x - y); }  template <typename t> double absminus (t x, t y) {     double sd = abs(x - y);     return sd; } 

operator overloading class:

minus operator-(minus &p, minus &q) {     return (p.something - q.something); }  double operator-(minus &p, minus &q) {     return (p.something() - q.something()); } 

when tried compile, gave me following error:

minus.h:25: error: new declaration ‘double operator-(minus&, minus&)’ minus.h:24: error: ambiguates old declaration ‘minus operator-(minus&, minus&)’ 

no, can't. overloading can done when parameter list different. example:

int myfun(int); double myfun(int); 

now calling myfun(10). compiler has no way determine version call.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -