Topic: Reference to Pointer
Author: Mull@zippo.com
Date: 1997/09/23 Raw View
Hi!,
Is this legal??
class A; // defined somewhere.
class B; // defined somewhere.
int A::allotMem(B*& b)
{
b = new B;
}
void someFunction()
{
B* b = 0;
A a;
a.allotMem(b);
}
My question is - will "b" point to the object alloted in the function
A::allotMem() or will it remain NULL after "return"ing from
A::allotMem().
This is supported my MSVC++ but not by HP compilers.
My HP-C++ compiler says it's an anachronism.
Compiler : HP C++ HPCPLUSPLUS A.10.22
TIA,
Mull.
[ chandru@hpsgns1.sgp.hp.com ]
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1997/09/24 Raw View
Mull@zippo.com writes:
|> Is this legal??
|>
|> class A; // defined somewhere.
|> class B; // defined somewhere.
|>
|> int A::allotMem(B*& b)
|> {
|> b = new B;
|> }
|>
|> void someFunction()
|> {
|> B* b = 0;
|> A a;
|> a.allotMem(b);
|> }
|>
|> My question is - will "b" point to the object alloted in the function
|> A::allotMem() or will it remain NULL after "return"ing from
|> A::allotMem().
It should point to the allocated object.
|> This is supported my MSVC++ but not by HP compilers.
You surprise me. I've done similar things with the HP compiler
(although not with the latest release).
|> My HP-C++ compiler says it's an anachronism.
|> Compiler : HP C++ HPCPLUSPLUS A.10.22
The anachronism message sounds like there is more to the expression than
just b. *If* the argument to A::allotMem is not an lvalue of the
correct type, the call is illegal. Since it was legal in earlier
versions of C++ (until about 6 or 7 years ago), many compilers (both HP
and Sun CC, for example) will only generate a warning about an
anachronism, rather than an error.
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
I'm looking for a job -- Je recherche du travail
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
Author: Dmitry Kochin <dukei@com2com.ru>
Date: 1997/09/26 Raw View
It is also supported by Borland compiler, but I know nothing about HP
one.
Mull@zippo.com wrote:
> Hi!,
>
> Is this legal??
>
> class A; // defined somewhere.
> class B; // defined somewhere.
>
> int A::allotMem(B*& b)
> {
> b = new B;
> }
>
> void someFunction()
> {
> B* b = 0;
> A a;
> a.allotMem(b);
> }
>
> My question is - will "b" point to the object alloted in the function
> A::allotMem() or will it remain NULL after "return"ing from
> A::allotMem().
>
> This is supported my MSVC++ but not by HP compilers.
>
> My HP-C++ compiler says it's an anachronism.
> Compiler : HP C++ HPCPLUSPLUS A.10.22
>
> TIA,
> Mull.
{Several sigs and banners snipped... please don't overquote. -mod}
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with
your
newsreader. If that fails, use
mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]