const引用参数 [英] const reference parameters

查看:130
本文介绍了const引用参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下声明之间有区别吗?

Is there a difference between the following declarations?

void somefunc(const Person &p);
void somefunc(Person const &p);


推荐答案

const 绑定到其左边的类型...除非它是声明的第一部分,在这种情况下它绑定到右边。

there is no difference. const binds to the type to its left...unless it is the first part of the declaration in which case it binds to the right.

请参阅: https://isocpp.org/wiki/faq/const -correctness#const-ref-alt

我个人认为 const T& x 读得更好。根据,Bjarne也倾向于将 const 第一。特别是因为关键字最初被称为 readonly readonly int x 更好地读取:-P。

Personally, I find that const T &x reads better. According to this, Bjarne also prefers to put the const first. Specifically because the keyword was originally going to be called readonly and readonly int x reads better :-P.

这篇关于const引用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆