Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-10-31 10:38:32


Should the following program compile?
GCC 3.0.1 says

example.cpp: In function `int main()':
example.cpp:20: call of overloaded `numeric_cast(double&)' is
ambiguous
example.cpp:2: candidates are: Out numeric_cast(In) [with Out =
   my_int<int>, In = double]
example.cpp:12: my_int<Digit> numeric_cast(double)
[with Digit = my_int<int>]

Is GCC right?
If yes, is there any other way
to this partial specialization/overload?

Helmut

----- Code ----
template<typename Out, typename In> Out numeric_cast(In in)
{
  Out o;
  return o;
}

template<typename Digit>
class my_int {};

template<typename Digit>
inline my_int<Digit> numeric_cast(double arg)
{
  my_int<Digit> result;
  return result;
}

int main()
{
  double a=5;
  my_int<int> j=numeric_cast<my_int<int> >(a);

  return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk