473,395 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ambiguous call to overloaded template function

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<intt1, t2;
swap(t1, t2);
swap(p1, p2);

Jun 30 '08 #1
1 4008
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
Jun 30 '08 #2

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

Similar topics

3
by: catcher | last post by:
template<typename T> void fun(T x) {}; void fun(int x) {}; int main() { fun<int>(3);
7
by: ishekara | last post by:
Hi, I am having a class template which is used to convert from one type another. I am having a problem when i use the copy constructor with same type. code. #include "stdio.h" template...
1
by: Alex Zhitlenok | last post by:
Hi, My question is how to resolve in C# ambiguous overloaded operators? Let say, I have two unrelated classes A and B, each one implements overloaded operator + with the first parameter of type...
2
by: pvl_google | last post by:
Hi, I'm trying to extend an STL class with additional iterator functionality. In the simplified example below I added an extra iterator class with a dereferencing operator. This operator...
4
by: Joseph Turian | last post by:
I have a templated class with the following methods: Vocab(const T& t); Vocab(unsigned uid); However, when T = unsigned, and I call Vocab(unsigned(0)) then the compiler rightly complains about...
3
by: valoh | last post by:
Hi, is this legal c++ code? template <typename BaseTstruct A { BaseT& this_() { return *static_cast<BaseT*>(this); } template <typename Tvoid Foo() { this_().Bar<T>(); } template...
9
by: sebastian | last post by:
I've simplified the situation quite a bit, but essentially I have something like this: struct foo { }; void bar( foo const & lhs, foo const & rhs )
8
by: Nikola | last post by:
Hello, I'm writing a String class for C++ and I'm getting the following error message when using operator: test.cpp: In function ‘int main()’: test.cpp:7: error: ISO C++ says that these are...
3
by: mathieu | last post by:
Could someone please tell me what is wrong with the following -ugly- piece of c++ code. Why when I explicititely set the template parameter my gcc compiler start getting confused: bla.cxx: In...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.