what’s the difference between following code, why one works and the other doesn’t?

i wanna define a function whose behavior depends on whether its parameter is pod type, i do this in two ways:

first

template <typename T, typename = typename std::enable_if<std::is_pod<T>::value>::type>
void f(const T&) {
    //...
}
template <typename T, typename = typename std::enable_if<!std::is_pod<T>::value>::type>>
void f(const T&) {
    //...
}

second

template <typename T>
typename std::enable_if<std::is_pod<T>::value>::type f(const T&) {
    //...
}
template <typename T>
typename std::enable_if<!std::is_pod<T>::value>::type f(const T&) {
    //...
}

the second works well while the first is error. compiler complains redefine f in the first case. I wanna know the difference between them. and why the first is error.

thanks for reading, please help me!.


Source: c++

Leave a Reply