help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Explicit instanciation of template function


From: jalina
Subject: Explicit instanciation of template function
Date: Wed, 28 Mar 2007 07:33:41 +0200
User-agent: Thunderbird 1.5.0.10 (X11/20070307)

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]