I want to define a function whose behavior depends on whether its pod parameter , I do this in two ways:
the 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, and the first is a mistake. the compiler complains about overriding f in the first case. I want to know the difference between the two. and why the first mistake.
Thanks for reading, please help me!
source
share