0
考虑下面的短节目:参考的烦躁不沾类型的模板函数
#include <type_traits>
#include <iostream>
using namespace std;
template <typename T>
void fn(T t) {
cout << "T is reference: " <<
boolalpha << is_reference<T>::value << endl;
}
int main(void) {
int x = 0;
int& r = x;
fn(r);
}
运行这个程序,我越来越: T为参考:假。
会是解释吗?
你没有使用完美的转发,只是正常的值复制。 – ildjarn 2012-03-23 17:05:51
如果你试图通过引用强制该函数,然后使签名'template void fn(T&t)'。如果目标是“尝试”is_reference,那么这将无济于事。 –
2012-03-23 17:26:19