Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!grace.cs.washington.edu!jeffb From: jeffb@grace.cs.washington.edu (Jeff Bowden) Newsgroups: comp.lang.c++ Subject: A question of references Summary: How do you declare a reference to a pointer to T? Message-ID: Date: 7 May 89 20:28:08 GMT Sender: news@beaver.cs.washington.edu Distribution: comp Organization: Ministry of Silly Walks Lines: 63 Here's the deal. I've got a function in C which I am translating to C++. Here is an abstraction of what the current function does: T *foo[ROWS][COLS]; /* ... */ void bar(/* args... */) { T **d = &foo[r][c]; /* Many uses of `d' all of the form ``(*d)'' */ } Obviously, `d' is crying out ``I'm really a reference!''. Now, since c++ has this nifty ability to specify references I would like to declare `d' as such and change all instances of ``(*d)'' to ``d''. Problem is, I can't figure out how to declare it. Obviously (?) it should be either T *&d = ... or T &*d = .... But which? And how, in general, do you figure it out? I think the relevant part of Stroustrup starts on page 269. To wit: ``Now imagine a declaration T D1 where `T' is a type-specifier (like `int', etc.) and `D1' is a declarator. ... If D1 has the form &D or & const D the type of the contained identifier is `... reference to T.' '' ^^^^^^^^^^ This leads me to think that either order doesn't matter or that in all cases the "&" has to be the first thing. The former seems unlikely so my guess is that T &*d = ... is what I want. Is my interpretation correct or is there some other place in Stroustrup which is more explicit about how references should really be declared. I realize that I could just test the possibilities out with a compiler but it seems as though this really ought to be clearly documented and I'd like to know where. -- Say "lah vee."