dimanche 3 janvier 2021

Why this is not a good implementation for checking the variable is a pointer or not? [closed]

Why this is not a good implementation for checking the variable is a pointer or not?

It seems work, here is the related code snippet:

#include<iostream>    

template <typename T>
bool is_pointer(T)
{
     return true;
}

template <typename T>
bool is_pointer(T*)
{
    return false;
}

int main()
{
    std::boolalpha(std::cout);

    int a;
    int *ptr;
    std::cout << is_pointer(a) << std::endl;
    std::cout << is_pointer(ptr) << std::endl;
}

Aucun commentaire:

Enregistrer un commentaire