template---decay

    xiaoxiao2022-07-07  192

    对于非引用类型的参数,在实参演绎的过程中会出现从数组到指针(array-to-pointer)的类型转变,称之为退化(decay)

    test.h

    #include<iostream> #include<typeinfo> template<class T> void ref(T& t) { std::cout << typeid(t).name() << std::endl; } template<class T> void noref(T t) { std::cout << typeid(t).name() << std::endl; }

    main.cpp

    ::ref("hei"); ::noref("hei");

    print:

    最新回复(0)