0

I need to overload basic operators to work with primitive types:

Frac - Common fraction class; Frac(a,b) = a/b. This is overload of operator >

template<typename t>
bool Frac::operator > (const t &right) {
if((long double)right)
    return ((long double)right < this->toLongDouble());
else
    cout << "Error!";
}

in main:

cout << ((Frac(1,2) > 2.5));

I have error:

 Error: undefined reference to `bool Frac::operator><double>(double const&)'
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
punksta
  • 2,738
  • 3
  • 23
  • 41
  • 2
    Where `bool Frac::operator >` is defined ? in a cpp (if so read [why-can-templates-only-be-implemented-in-the-header-file](http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file))? – Jarod42 Feb 12 '14 at 11:22
  • Error suggests that the template was not instantiated. It this template definition in header or in cpp? – Bogdan Feb 12 '14 at 11:23
  • 1
    BTW: should be const : `bool Frac::operator > (const t &right) const`. And I don't think that `if ((long double)right)` do what you want... – Jarod42 Feb 12 '14 at 11:26

0 Answers0