T fref(const T&, const T&);中的const T&,是什么意思?

[复制链接]
查看11 | 回复1 | 2008-12-11 22:22:17 | 显示全部楼层 |阅读模式
T fref(const T&, const T&);中的const T&,是什么意思?是reference arguments的话&后面不是有一个value的吧?(象const T&x,const T&y);
templateT fobj(T, T); // arguments are copied

template

T fref(const T&, const T&);
// reference arguments

string s1("a value");

const string s2("another value");

fobj(s1, s2);
// ok: calls f(string, string), const is ignored

fref(s1, s2);
// ok: non const object s1 converted to const reference

int 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

回复

使用道具 举报

千问 | 2008-12-11 22:22:17 | 显示全部楼层
后面应该是有一个形参的,就像const T&x,const T&y这样。加了const只不过是说后面引用的这个参数在函数内部不能改变,是一个常值。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行