C++函数参数作为参考
我有一个问题。谁能告诉我为什么有人会这样声明参数r
?
Record 和 Record 有什么区别? r 和记录(&r) ?
QDataStream& operator>>(QDataStream &s, Record(&r))
{
}
谢谢 :)
I have a question. Can anyone tell me why someone would declare parameter r
like that ?
Whats the difference between Record& r and Record(&r) ?
QDataStream& operator>>(QDataStream &s, Record(&r))
{
}
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Record(&r)
和Record &r
是相同的类型声明。我不知道为什么有人会包含括号,除非出于风格原因。也许这是重构留下的一些残渣?Record(&r)
andRecord &r
are identical type declarations. I don't know why somebody would include the parentheses except for stylistic reasons. Perhaps it's some cruft left over from a refactoring?正如理查德所说,Record (&r) 和 Record &r 是等价的。因此,重要的区别在于它们如何有效地传达程序员的意图。我个人更喜欢Record& r 优于 Record &r 因为我喜欢将类型与名称分开。也就是说,我会避免使用 Record (&r),因为它看起来与函数类型的语法非常相似。例如,Record (&r)() 会将 r 声明为对如下函数的引用。
As Richard said Record (&r) and Record &r are equivalent. So the important difference is how effectively they communicate the intent of programmer. I personally prefer Record& r over Record &r because I like to separate the type from the name. That said, I would avoid the Record (&r) because it looks so similar to the syntax for function types. For example, Record (&r)() would declare r as a reference to a function such as the following.