N
none
I am trying to understand SFINAE based on this wiki page:
http://en.wikipedia.org/wiki/SFINAE
// Defines return type to be void for all types
// besides int.
template<typename T>
struct can_use_f {
typedef void type;
};
template<>
struct can_use_f<int> {
typedef int type;
};
// function with return type ::type.
template<typename T>
typename can_use_f<T>::type f(T const &);
int main() {
f(1);
f(1.);
}
I have made a slight modification so if f(1) is called f should have
return type int. But it gives the error:
/tmp/cclJK0dJ.o: In function `main':
bob.cpp.text+0x95): undefined reference to `can_use_f<int>::type
f<int>(int const&)'
bob.cpp.text+0xa5): undefined reference to `can_use_f<double>::type
f<double>(double const&)'
collect2: ld returned 1 exit status
Is this the correct execution steps:
1) f(T const &) is called.
2) the return type is decided based on the template parameter.
3) if T != int return type is void. If T = int return type should be int
(this does not work).
http://en.wikipedia.org/wiki/SFINAE
// Defines return type to be void for all types
// besides int.
template<typename T>
struct can_use_f {
typedef void type;
};
template<>
struct can_use_f<int> {
typedef int type;
};
// function with return type ::type.
template<typename T>
typename can_use_f<T>::type f(T const &);
int main() {
f(1);
f(1.);
}
I have made a slight modification so if f(1) is called f should have
return type int. But it gives the error:
/tmp/cclJK0dJ.o: In function `main':
bob.cpp.text+0x95): undefined reference to `can_use_f<int>::type
f<int>(int const&)'
bob.cpp.text+0xa5): undefined reference to `can_use_f<double>::type
f<double>(double const&)'
collect2: ld returned 1 exit status
Is this the correct execution steps:
1) f(T const &) is called.
2) the return type is decided based on the template parameter.
3) if T != int return type is void. If T = int return type should be int
(this does not work).