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:
在這裏插入圖片描述

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