Author Topic: C++ limitations  (Read 2475 times)

0 Members and 1 Guest are viewing this topic.

Offline nslay

  • Hero Member
  • *****
  • Posts: 786
  • Giraffe meat, mmm
    • View Profile
C++ limitations
« on: February 04, 2009, 11:18:18 am »
I always feel the grass is greener on the other side when it comes to C and C++
When in C, I look at C++ and think how great STL is.
When in C++, I look at C and think how much more flexible it is.

However, one thing that really annoys me about C++ that is easily accomplished in C is partial construction of objects.

For example, say you have a hierarchy of inheritance of objects and you have static factory functions in each.  Factory functions are useful in situations where you don't know the specific type of object to construct.  For example, you might need to read variable types of objects from a file ... this cannot be accomplished with ordinary constructors.  Ideally, the hierarchy of factory functions deal specifically with reading data specific to their object.  However, you run into a boot strap problem (you want to lift yourself up with your own boot straps).  The parent factory acquires an object from a child factory that is determined at run time...but the child factory might need parent-specific data to invoke the parent's constructor to construct itself to begin with.

Why can't C++ allow partial constructors and allow the programmer to manually bind objects?
Code: [Select]
Base *base = new partial Base; // Only Base is constructed...Base could be purely abstract
Derived *derived = new partial Derived; // Only Derived is constructed

bind_objects(base,derived); // Now base is bound to derived

Rebinding objects would be nice too.

Inheritance is a run-time feature...why try to hide this fact?  There's no good reason to disallow partial constructors or manual binding of objects.
An adorable giant isopod!