Topic: Passing a pointer by reference
Author: karim@info.polymtl.ca (Aktouf Karim)
Date: Tue, 17 Aug 1993 13:55:15 GMT Raw View
Hi,
Is there a way in C++ for passing a pointer by reference? For example,
a function receives a head pointer to a chained list as argument and may have to
allocate memory (thus the HeadPtr will be assigned an address) if the list is
empty or may have to make the head point to another element in the list...
Thanks!
Karim
--
| Irikar Le Maure | Ecole : karim@info.polymtl.ca |
| Je pense, donc je nuis | Boulot: karim@alex.qc.ca |
|----------------------------------------------------------|
| Ecole Polytechnique de Montreal - Alex Informatique Inc. |
.. il n'entrerait dans la saintete, aux yeux de Dieu, que
s'il rentrait dans l'infamie aux yeux des hommes.
Victor Hugo, "Les miserables".
Author: kocher@us-es.sel.de (Hartmut Kocher US/ESA)
Date: Tue, 17 Aug 93 15:25:27 GMT Raw View
In article <1993Aug17.135515.4421@vlsi.polymtl.ca>, karim@info.polymtl.ca (Aktouf Karim) writes:
> Is there a way in C++ for passing a pointer by reference? For example,
> a function receives a head pointer to a chained list as argument and may have to
> allocate memory (thus the HeadPtr will be assigned an address) if the list is
> empty or may have to make the head point to another element in the list...
> --
> | Irikar Le Maure | Ecole : karim@info.polymtl.ca |
> | Je pense, donc je nuis | Boulot: karim@alex.qc.ca |
> |----------------------------------------------------------|
> | Ecole Polytechnique de Montreal - Alex Informatique Inc. |
>
> .. il n'entrerait dans la saintete, aux yeux de Dieu, que
> s'il rentrait dans l'infamie aux yeux des hommes.
> Victor Hugo, "Les miserables".
Easy: void ChangeHeader(ListNode * & headPtr);
Cheers
Hartmut
--
+==============================|==============================+
| Hartmut Kocher | |
| Technical Consultant | All opinions expressed here |
| Rational GmbH | are my own. |
| Rosenstrasse 7 | |
| Pullach im Isartal | I know you guessed it, |
| Germany | but it keeps my lawyer happy.|
| Email: Kocher@us-es.sel.de | |
+==============================|==============================+
Author: joe@bftsi0.UUCP (Joe Foster of Borg)
Date: 20 Aug 93 05:33:11 GMT Raw View
In article <1993Aug17.135515.4421@vlsi.polymtl.ca>, karim@info.polymtl.ca (Aktouf Karim) writes:
> Hi,
>
> Is there a way in C++ for passing a pointer by reference? For example,
> a function receives a head pointer to a chained list as argument and may have to
> allocate memory (thus the HeadPtr will be assigned an address) if the list is
> empty or may have to make the head point to another element in the list...
This program will print out "1":
#include <stream.h>
void foomangle(void* &foo) { foo = (void*)1; }
main()
{
void* foo = 0;
foomangle(foo);
cout << (long)foo << '\n';
return 0;
}
Hope this helps!
Joe Foster
joe@bftsi0.uucp