ambiguous call to overloaded template function

Discussion in 'C++' started by Ruki, Jun 30, 2008.

  1. Ruki

    Ruki Guest

    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);
     
    Ruki, Jun 30, 2008
    #1
    1. Advertising

  2. Ruki

    Ruki Guest


    > 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
     
    Ruki, Jun 30, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ishekara

    ambiguous call to overloaded

    ishekara, Feb 25, 2005, in forum: C++
    Replies:
    7
    Views:
    6,508
    red floyd
    Feb 25, 2005
  2. rolandz
    Replies:
    5
    Views:
    519
    Jim Langston
    Jul 4, 2006
  3. , India
    Replies:
    1
    Views:
    408
    Kai-Uwe Bux
    Sep 10, 2007
  4. Joseph Turian

    Ambiguous call to overloaded function

    Joseph Turian, Dec 20, 2007, in forum: C++
    Replies:
    4
    Views:
    532
    tragomaskhalos
    Dec 20, 2007
  5. mast4as
    Replies:
    3
    Views:
    519
    mast4as
    Jul 4, 2011
Loading...

Share This Page