Thanks for the remark Kris.  I had thought of that, but unfortunately, the two-step approach is necessary since I'm using a handle-to-data approach.  The actual pointers (objects) associated with the handles may change, and the (possibly incremental) init needs to be re-run for the object.

  Brian


On Wed, Nov 7, 2012 at 3:17 PM, Krzysztof Czainski <1czajnik@gmail.com> wrote:
2012/11/8 Brian Budge <brian.budge@gmail.com>
Hi all -

I have a case where I have a largeish inheritance hierarchy.  I will be calling an initialization function on all objects before using them in some fashion.

Basically what I need to happen is when I call init() on a Foo the following would occur:

void Foo::init() {
    super::init();
    // now with the knowledge that anything I inherited is set up, I can set myself up...
}

It is not necessary for every call to implement init, in which case the behavior should be that the call is propagated up the inheritance chain (which it is by default in C++).

In order to make this work, I need to write different code for "super" in every class implementation, which is a bit error prone.  Even if I don't copy/paste, my brain might be on autopilot and type something further up the inheritance chain than it should be.  Alternatively, I could require that each class provides a typedef for super, but I'm still relying on myself to remember to call super's init function.

Is there anything in boost that would support this kind of hierarchy traversal (semi-)automatically?  If there is not, are there suggestions for ways to implement this in a less error-prone fashion?

Thanks,
  Brian

I think the constructors in C++ work the way you want init() to work. You probably use two-step initialization, don't you? Can you avoid it?

Regards,
Kris

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users