472,328 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

function template specialization ambiguity

Consider the following code:
template <class T>
void f(T, int) {}
template <class T>
void f(int, T) {}
template<>
void f(int, int) {} // ambiguous ?

My compiler complains that the last definition is an "ambiguous template
specialization `f<>' for `void f(int, int)' ". I have tested this on a
few compilers and all they complain there. What is wrong in this
specialization ? Consider similar code:
template <class T, class C>
void f(int, T, C) {}
template <class T, class C>
void f(T, int, C) {}
template<class C>
void f(int, int, C) {}

Compiler does not complain that 3rd function is ambiguous. Why ? What is
the difference ?
Rafal
--
sed -e s/s/a/g <my_address >my_right_address
Jul 22 '05 #1
1 2381
Rafal Dabrowa wrote in news:co**********@news.onet.pl in comp.lang.c++:
Consider the following code:
template <class T>
void f(T, int) {}
template <class T>
void f(int, T) {}
template<>
void f(int, int) {} // ambiguous ?

My compiler complains that the last definition is an "ambiguous
template
specialization `f<>' for `void f(int, int)' ". I have tested this on a
few compilers and all they complain there. What is wrong in this
specialization ? Consider similar code:
template <class T, class C>
void f(int, T, C) {}
template <class T, class C>
void f(T, int, C) {}
template<class C>
void f(int, int, C) {}

Compiler does not complain that 3rd function is ambiguous. Why ? What
is the difference ?

The diffrence is that in the second example you aren't
specializing anything, you are just providing an overload
that happens to be a template.

In the first example the explicit specialization f<>(int, int)
could be a specialization of either of the two overloads that
preceded it, hence the ambiguity.

HTH.
--
sed -e s/s/a/g <my_address >my_right_address


Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ivan | last post by:
How (at compile time) can one determine whether some class implements a particular member function? Name only is sufficient, full signature match...
4
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a...
7
by: CoolPint | last post by:
While I was testing my understanding of Functioin Template features by playing with simple function templates, I got into a problem which I cannot...
2
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func();...
12
by: RA Scheltema | last post by:
Hi all, I have the following code: namespace A { inline void func(int) { ...; } inline void func(float) { ...; } inline void...
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T...
5
by: desktop | last post by:
I have this example: template<class T(1) void f( T ); template<class T(2) void f( T* ); template< (3)
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.