Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Reference to pinter

Reply
Thread Tools

Reference to pinter

 
 
Fab
Guest
Posts: n/a
 
      05-29-2013
Dear all

I was browsing the OpenFOAM sources a little and I stumbled over types
of the form

T * Tp ( 0 );
T *& Tpr( Tp );

In what particular situation would something like this be useful? I can
only think of that the reference must be initialized?

I am thankful for any feedback!

Thanks
Fab
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      05-29-2013
On Wed, 2013-05-29, Fab wrote:
> Dear all
>
> I was browsing the OpenFOAM sources a little and I stumbled over types
> of the form
>
> T * Tp ( 0 );
> T *& Tpr( Tp );
>
> In what particular situation would something like this be useful?


In the situation that applies in OpenFOAM, maybe? What does the rest
of the code tell you?

That said, it seems to me this just creates another (badly chosen)
name "Tpr" for Tp. I fail to see the usefulness of that, but perhaps
I'm missing something.

Sometimes I create references for readability or constness reasons, e.g.

map<int, string>::iterator it = foo();
const string& name = it->second;
// use name instead of it->second

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
 
gwowen
Guest
Posts: n/a
 
      05-29-2013
On May 29, 7:46*am, Fab <(E-Mail Removed)> wrote:
> In what particular situation would something like this be useful?


Maybe in Old Times, after a Tea Party, or A Night Out. Or perhaps by
The Caretaker, The Lover, The Dumb Waiter or any time you fell A
Slight Ache for an adaption of A Remembrance Of Things Past.
 
Reply With Quote
 
Marcel Müller
Guest
Posts: n/a
 
      05-30-2013
On 29.05.13 08.46, Fab wrote:
> I was browsing the OpenFOAM sources a little and I stumbled over types
> of the form
>
> T * Tp ( 0 );
> T *& Tpr( Tp );
>
> In what particular situation would something like this be useful? I can
> only think of that the reference must be initialized?


I am using this from time to time.

Example 1:
// Array of pointers to T, that owns it's elements.
template <class T>
class my_vector<T>
{
...
// Add initial (NULL) element
T*& append();
};

class my_element
{ ...
};

my_vector<my_element> array;
array.append() = new my_element();


Example 2:

class my_queue
{
entry* Head;
...
void insert(entry* elem, entry* after)
{ entry*& qp = after ? after->Next : Head;
entry->Next = qp;
qp = elem;
}
}


Marcel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How could I use a pinter array to manipulate several 2D arrays? Cuthbert C Programming 3 03-18-2011 11:35 AM
pinter = string. JoeC C++ 6 06-23-2007 03:52 AM
integer to pinter conversion junky_fellow@yahoo.co.in C Programming 31 09-20-2005 10:29 PM
integer to pinter conversion junky_fellow@yahoo.co.in C Programming 3 09-14-2005 08:33 AM
How to tell if a reference is project or file reference from within the IDE? Darren ASP .Net 0 10-11-2004 12:51 AM



Advertisments