I am learning C++ using gcc but I can not get the following to compile:

#include <iostream>
#include <string>

using namespace std;

template<typename T>
void my_swap(T& v1, T& v2)
{
    cout << "swap - sizeof(T): " << sizeof(T) << "\n";
    T tmp = v1;
    v1 = v2;
    v2 = tmp;
}

int main()
{
    char i = 'a';
    char j = 'b';
    cout << "sizeof(char) = " << sizeof(char) << "\n";
    cout << "sizeof(int) = " << sizeof(int) << "\n";
    my_swap(i, j);
my_swap<int>(i, j); // <= /tmp/tmpl.cc|22| error: no matching function for call to ‘my_swap(char&, char&)’
}

Is it a known behavior ? bug in my compiler (gcc 4.1.2, ubuntu) ? ... ?

Thanks
J.

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to