T fref(const T&, const T&);中的const T&,是什么意思?是reference arguments的話&后面不是有一個(gè)value的吧?(象const T&x,const T&y);template <typename T> T fobj(T, T); // arguments are copiedtemplate <typename T>T fref(const T&, const T&); // reference argumentsstring s1("a value");const string s2("another value");fobj(s1, s2); // ok: calls f(string, string), const is ignoredfref(s1, s2); // ok: non const object s1 converted to const referenceint a[10], b[42];fobj(a, b); // ok: calls f(int*, int*)fref(a, b); // error: array types don't match; arguments aren't converted to pointers
1 回答

江戶川亂折騰
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
后面應(yīng)該是有一個(gè)形參的,就像const T&x,const T&y這樣。加了const只不過是說后面引用的這個(gè)參數(shù)在函數(shù)內(nèi)部不能改變,是一個(gè)常值。
- 1 回答
- 0 關(guān)注
- 318 瀏覽
添加回答
舉報(bào)
0/150
提交
取消