Ambigous call to a function

I have four functions:

template<class Exception,class Argument>
 void allocate_help(const Argument& arg,Int2Type<true>)const;

 template<class Exception,class Argument>
 std::nullptr_t allocate_help(const Argument& arg,Int2Type<false>)const;

 template<class Exception>
 void allocate_help(const Exception& ex,Int2Type<true>)const;

 template<class Exception>
 std::nullptr_t allocate_help(const Exception& ex,Int2Type<false>)const;

but when I call:

allocate_help<std::bad_alloc>(e,Int2Type<true>()); //here e is of a std::bad_alloc type 

I'm getting an error: Error 3 error C2668: ambiguous call to overloaded function Why?

Answers


Because your call matches both:

template<class Exception,class Argument>
 void allocate_help(const Argument& arg,Int2Type<true>)const;

with Exception = std::bad_alloc and Argument = std::bad_alloc (Argument is automatically deduced), and:

template<class Exception>
 void allocate_help(const Exception& ex,Int2Type<true>)const;

with Exception = std::bad_alloc. Hence the ambiguity of the call.

Also I think that your compiler should output all the matching function after the error line, so you could answer your question yourself.


Because they are ambigious.

template<class Exception,class Argument>
std::nullptr_t allocate_help(const Argument& arg,Int2Type<true>)const;

template<class Exception>
std::nullptr_t allocate_help(const Exception& ex,Int2Type<true>)const;

The signature of the second function is a subset of the first one, which means that in the context of your function call they are the same of taking "any type" as first argument and Int2Type as second argument.

allocate_help<std::bad_alloc>(e,Int2Type<true>());

Can become either:

std::nullptr_t allocate_help<std::bad_alloc, std::bad_alloc>(const std::bad_alloc& arg,Int2Type<true>)const;

or

 std::nullptr_t allocate_help<std::bad_alloc>(const std::bad_alloc& ex,Int2Type<true>)const;

How would the compiler choose?


Need Your Help

capturing javascript events in c#

c# javascript events

I'm running google earth in a web browser that is embedded in a c# app. I have captured an event through javascript that fires when the user right clicks on the globe. How can I bubble an event to go

FTP Client not accepting welcome message

ftp response wireshark filezilla

Alright so, I was developing a FTP Server on port 2121 as apart of a much larger project.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.