我有以下计划:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:background="@color/white_pure">
我希望这是因为#include<stdio.h>
template<class T> void f(T t) {
t += 1;
}
template<class T> void g(T &t) {
t += 10;
}
int main()
{
int n=0;
int&i=n;
f(i);
g(i);
printf("%d\n",n);
return 0;
}
是对i
的引用,所以我希望模板函数n
应该为模板类型f
获取int&
。但事实上它没有。该计划的输出为T
,而不是我预期的10
。
所以我的问题是,对于11
,为什么f
匹配T
而不是int
变量int&
?这背后的规则是什么?
感谢。