Re: Usage of pointer to object under construction
From: Dave (better_cs_now_at_yahoo.com)
Date: 01/11/05
- Next message: Dave: "Re: C++ book?"
- Previous message: zxxgp: "C++ book?"
- In reply to: Victor Bazarov: "Re: Usage of pointer to object under construction"
- Next in thread: Victor Bazarov: "Re: Usage of pointer to object under construction"
- Reply: Victor Bazarov: "Re: Usage of pointer to object under construction"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 11 Jan 2005 10:34:33 -0700
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:ZGTEd.35054$NC6.17848@newsread1.mlpsca01.us.to.verio.net...
> Dave wrote:
> > In the code below, I use a pointer to an object under construction. Is
the
> > usage below legal? I have come across similar code at work. It
compiles,
> > but I'm not sure it's really legal...
> >
> > Thanks,
> > Dave
> >
> > struct D;
> >
> > struct B
> > {
> > B(D *);
> > };
> >
> > struct D: B
> > {
> > D(): B(this) {}
> > };
>
>
> There is no _usage_ here. To show _usage_ you need to post the _body_ of
> the B's constructor.
>
> Victor
Your response implies the code, as much of it as was shown, is legal. There
may or may not be something illegal going on in B::B(), but there also may
or may
not being something illegal going on in
SomeClassInAnotherProgram::SomeClassInAnotherProgram().
It wasn't really the point, hence the omission. Of course, I cannot invoke
member
functions, for just one thing, via the pointer because those member
functions may
refer to object state not yet itself constructed.
But let's suppose for the sake of argument that B::B() is as shown below.
Perhaps
my question should have been: Is it legal to __mention__ a pointer to an
object
under construction?
struct D;
struct B
{
B(D *p): ptr_to_superobject(p) {}
D *ptr_to_superobject;
};
struct D: B
{
D(): B(this) {}
};
- Next message: Dave: "Re: C++ book?"
- Previous message: zxxgp: "C++ book?"
- In reply to: Victor Bazarov: "Re: Usage of pointer to object under construction"
- Next in thread: Victor Bazarov: "Re: Usage of pointer to object under construction"
- Reply: Victor Bazarov: "Re: Usage of pointer to object under construction"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|