what was wrong with struct & class in C++?

Bill Baxter dnewsgroup at billbaxter.com
Sun Dec 16 13:09:57 PST 2007


Bill Baxter wrote:
> Bill Baxter wrote:
>> Yigal Chripun wrote:

> There is one problem with that solution.  classinfo.create only works if 
> the object being duplicated has a default constructor.  If you split it 
> into dup and copy, then you can have the most derived class create the 
> instance, calling whatever constructor it wants to.
> 
> I'm not sure why classinfo.create returns null though.  The doc for it 
> only says "Create instance of Object represented by 'this'.".  Doesn't 
> mention anything about ever returning null.

Another problem is that it's far too easy for derived classes to forget 
that they need to implement their own dup(), so you end up with what's 
effectively another variation of the slicing problem.  You get an object 
that's a Derived but for some reason all the Derived-specific members 
are bogus.  I suppose it's not quite as bad as the real slicing problem 
though, because once detected it can always be fixed at the source, 
whereas with slicing, the line of code needing fixing could be anywhere.

And that problem exists with the split dup/copy solution too.

--bb



More information about the Digitalmars-d mailing list