Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- THIS DOESN'T WORK: undefined reference to `int asd<int, 0>(int*)'
- #include <type_traits>
- #include <iostream>
- using namespace std;
- template <typename T, typename enable_if< is_array<T>::value, int >::type =0 > int asd(T*){
- cout<<"This is for arrays"<<endl;
- return 0;
- }
- template <typename T, typename enable_if< !is_array<T>::value, int >::type =0 > int asd(T*){
- cout<<"This is for NON arrays"<<endl;
- return 0;
- }
- int main() {
- int dummy=3;
- int (*voided)(void*)=(int (*)(void*))asd<decltype(dummy)>;
- voided(&dummy);
- }
- THIS DOES:
- #include <type_traits>
- #include <iostream>
- using namespace std;
- template <typename T, typename enable_if< is_array<T>::value, int >::type =0 > int asd(T*){
- cout<<"This is for arrays"<<endl;
- return 0;
- }
- template <typename T, typename enable_if< !is_array<T>::value, int >::type =0 > int asd(T*){
- cout<<"This is for NON arrays"<<endl;
- return 0;
- }
- int main() {
- int dummy=3;
- int (*temp)(decltype(dummy)*)=asd<decltype(dummy)>;
- int (*voided)(void*)=(int (*)(void*))temp;
- voided(&dummy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement