Re: Usage of pointer to object under construction

From: Dave (better_cs_now_at_yahoo.com)
Date: 01/11/05


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) {}
};



Relevant Pages

  • Re: Usage of pointer to object under construction
    ... Dave wrote: ... I use a pointer to an object under construction. ... > usage below legal? ... > struct D; ...
    (comp.lang.cpp)
  • Re: T val = ({ semicolon_separated_statements });
    ... > of the struct in which that element is contained. ... alignment issues) if pmm didn't actually point to a mine. ... Tthe original construction of '__mptr' is entirely ... pointer type always gives a null pointer. ...
    (comp.lang.cpp)
  • Usage of pointer to object under construction
    ... I use a pointer to an object under construction. ... usage below legal? ...
    (comp.lang.cpp)
  • Re: Question on LSP
    ... Because construction paradigms have different goals. ... But that has nothing to do with what a pointer type ... But that does not mean that the semantics of an object reference is ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • [PATCH] KEYS: Make request_key() and co fundamentally asynchronous
    ... completion function for the key type to indicate completion of construction. ... Or by userspace invoking the request_key system call: ... -author fills in a struct key_type and registers it with the system. ...
    (Linux-Kernel)