Topic: Improved handling for partially constructed objects?
Author: nobody@nowhere.com ("Anonymous")
  Date: Mon, 24 Feb 2003 19:56:13 +0000 (UTC) Raw View
"John Nagle" <nagle@animats.com> wrote in message
news:JsT2a.302$9G2.40698922@newssvr14.news.prodigy.com...
> Over the years, C++ has acquired more attributes (volatile,
> mutable, explicit) to deal with similar ambiguous situations.
> What's needed here is a way to say "under construction".
> This leads to restrictions similar to those for an
> class whose declaration isn't visible - pointers to
> it can be manipulated, but you can't access its members.
This fits in my idea of private variables. For example,
struct S {int x; private: int y;};
 int main()
{
   S s;
   private S& ref = s;
   ref.x = 3; //Error; cannot access member of private structure 'ref'
   public S& ref2 = private_cast<public S&>(s);
   ref.y = 4; //OK.
}
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]
Author: nagle@animats.com (John Nagle)
  Date: Mon, 17 Feb 2003 17:07:57 +0000 (UTC) Raw View
   One common construct is a backpointer, where one object
creates another object that points back to the first.
 class B;
 class A {
 private:
  B& owned;
 public:
  A();
 };
 class B {
 private:
  A& owner;
 public:
  B(A& myowner)
  : owner(myowner) {}
 };
A::A()    // constructor implementation
{ owned = *new B(*this); }  // ILLEGAL - passed unconstructed "this"
This is a common, although illegal, idiom.  It should
be regularized.
Over the years, C++ has acquired more attributes (volatile,
mutable, explicit) to deal with similar ambiguous situations.
What's needed here is a way to say "under construction".
This leads to restrictions similar to those for an
class whose declaration isn't visible - pointers to
it can be manipulated, but you can't access its members.
Comments?
    John Nagle
    Animats
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]