[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

function template overloading and parameter deduction c++03 standard con

From: petr . zika
Subject: function template overloading and parameter deduction c++03 standard conformance
Date: Fri, 21 Sep 2007 14:07:59 -0700
User-agent: G2/1.0

Basically, what I need is a set of templated functions with the first
type parameter to be specified explicitly and the rest of type
parameters as types for the function parameters.

The code at the end of the post compiled with
g++ -ansi -pedantic
compiles successfully in version 4.1.2, but fails in 3.4.6 with the
following error: In function `int main()': error: call of overloaded `foo(const int&)' is
ambiguous note: candidates are: T foo(P&) [with T = int, P = const
int] note:                 T foo(const P&) [with T = int, P =
It may seem that if it compiles in the new version, it was simply a
bug fixed, but I found some discussion regarding similar problem,
stating that the code is invalid in c++03 standard and that the c++0x
standard will contain modifications allowing such construct to work.

I really need the c++03 standard conformance, so my questions are: Is
this code legal in the c++03 standard or not? Is there an alternate
conforming way to achieve similar results?

Thank you for any insight.

template <typename T, typename P>
T foo(P &p)
template <typename T, typename P>
T foo(const P &p)
int main()
   const int &x = 1;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]