Topic: Template function & overload resolution


Author: fwai@armltd.co.uk (Francis Wai)
Date: 1996/07/12
Raw View
In 14.10.5 Clause 5, the DWP (Oct '95) gave the following example,

  template <class T> T max(T a, T b) { return a > b ? a : b; }
  int max(int a, int b) { return a > b ? a : b; }

  void f(int x, int y) {
    max (x, y);  // error: duplicate definition of max()
  }

Is there an explanation why this is the case? Given that the previous
section 14.10.4 clearly indicates that any instance of a template
function would have been mangled taking into account the template
parameters of the primary template, this can hardly be a case of
duplicate definition.

I would imagine this being an ambiguity error since there would have
been two candidates for overload resolution both of which have
exactly the same signature. Any idea?

--Francis
--
e-mail: fwai@armltd.co.uk
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]