template --- decay

对于非引用类型的参数,在实参演绎的过程中会出现从数组到指针(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:
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章