Friday, April 30, 2010

Syntax for specializing function templates

Programmer Question

Is there a difference between the following approaches?



// approach 1
namespace std
{
template<>
void swap<Foo>(Foo& x, Foo& y) // note the <Foo>
{
x.swap(y);
}
}

// approach 2
namespace std
{
template<>
void swap(Foo& x, Foo& y)
{
x.swap(y);
}
}


I stumpled upon this when I tried to specialize swap for my own string type and noticed that swap<::string> doesn't work, but for a completely different reason :)



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails