samedi 25 avril 2015

call of overloaded 'swap(char&, char&)' is ambiguous


I can't figure out what is ambiguous about swap(arr[i++],arr[n--]); below. Please educate me on my wrongful ways.

#include <iostream>
#include <string>

template <typename T> void swap ( T & a, T & b )
{
    T temp = b;
    b = a;
    a = temp;
}

template <typename T> void reverse_array ( T * arr, size_t n )
{
   size_t i = 0;
   while (i < n) swap(arr[i++],arr[n--]); // problem line
}


int main () 
{
   char mystr [] = "Obama smokes";
   reverse_array(mystr, sizeof(mystr)/sizeof(char));
   return 0;
}


Aucun commentaire:

Enregistrer un commentaire