Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > ambiguous call to overloaded template function

Reply
Thread Tools

ambiguous call to overloaded template function

 
 
Ruki
Guest
Posts: n/a
 
      06-30-2008
I want to overload function to swap two others types, for example,
type<T>, T* and so on,
but I can't compile the following code at VC 6.0.

The compiler says :
error C2667: 'swap' : none of 2 overload have a best conversion
error C2668: 'swap' : ambiguous call to overloaded function
-------------------------------------------------------------------------------------------------------------
template < typename T >
void swap(T &lhs, T &rhs)
{
// do some thing
}

template < typename T >
void swap(T *lhs, T *rhs)
{
// do some thing
}

template < typename T >
struct type{};

template < typename T >
void swap(type<T> &lhs, type<T> &rhs)
{
// do some thing
}
int main()
{
int *p1,*p2;
type<int> t1, t2;
swap(t1, t2);
swap(p1, p2);

 
Reply With Quote
 
 
 
 
Ruki
Guest
Posts: n/a
 
      06-30-2008

> Alf P. Steinbach:


>Don't use VC6, it's old.

I need compiler compatibility

>Why don't you just use std::swap instead of defining your own?

I also need use std::swap specialization for my own types even if i
use std::swap
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
call of overloaded is ambiguous: functions using template classes mast4as C++ 3 07-04-2011 06:20 AM
Ambiguous call to overloaded function Joseph Turian C++ 4 12-20-2007 11:24 AM
ambiguous call to overloaded function subramanian100in@yahoo.com, India C++ 1 09-10-2007 04:00 AM
[VC++ 6.0] Ambiguous call to overloaded function rolandz C++ 5 07-04-2006 02:20 PM
ambiguous call to overloaded ishekara C++ 7 02-25-2005 09:27 PM



Advertisments