views:

186

answers:

2

Hi, 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 :)

+10  A: 

Record(&r) and Record &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?

Richard Cook
T.E.D.
It was just an example from a book. Thanks for your help
Seba
Would you mind marking this answer as "accepted"? Thanks!
Richard Cook
No need to pressure, see e.g. the [FAQ](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work/5235#5235): *"It is generally accepted that you should wait 24 to 48 hours to let a bunch of people have a chance to answer your question. A question with an accepted answer may deter people from looking at a question."*
Georg Fritzsche
Sorry for my impatience! I'm a noob and just figuring out the etiquette. Thanks for the info!
Richard Cook
A: 

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.

Record f() { }
Bowie Owens