[webkit-dev] Why Foo& bar and not Foo &bar?
mjs at apple.com
Thu Sep 15 17:40:41 PDT 2005
On Sep 15, 2005, at 5:28 PM, Eric Seidel wrote:
> Pointer and reference types - pointer types should be written with
> a space between the type name and the * (so the * is adjacent to
> the following identifier if any). For reference types, the & goes
> next to the type name.
It makes more sense in C++ to think of reference-ness as part of the
type. In fact, many C++ programmers will also write the * next to the
type name, but we decided not to do this to avoid diverging from the
typical ObjC and C practice. Another way to think of it is that a Foo
* is accessed through different syntax than a Foo (you use * to get
the value, -> to dereference a field or method, etc), but a Foo&
behaves syntactically just like a Foo. If you declare "Foo *bar" then
indeed "*bar" has type Foo, but if you declare "Foo &bar" it is not
the case that "&bar" has type Foo, in fact it will have type "Foo *".
It only makes sense to say bar has type "Foo&".
> What if you write:
> Foo& bar, & baz?
We don't like multiple declarations on one line either, proper style
for this would be:
But even that is not right, because you can't declare a reference
without initializing it (unseated references are forbidden in C++),
and you also rarely want a reference as a local variable.
> Makes no sense to me.
> webkit-dev mailing list
> webkit-dev at opendarwin.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev