I can't comment on your answer, although this should be a comment and not an answer.. But anyway.
I'll start by saying that I'm not really sure about this, but I think that your solution using a "Base to Derived" constructor has a couple of issues.
First, if you would have any members in your DerivedClass that's not members of your BaseClass, then those would be initalised to their default values when the DerivedClass(const BaseClass& src)
is called. This may normally not be a problem, but this is probably implicitly called when you use the
DerivedClass someObject = ++someDerivedClassObject;
the compiler probably calls it as:
DerivedClass someObject = DerivedClass(++((BaseClass)someDerivedObject));
Secondary, since this is creating a new object, you might get unexpected results if you ever pass a DerivedClass-object by-reference or by-address to some function and expect a side-effect, as the ++
creates a new object.
This might, however be exactly the behaviour that you are looking for if you have a postfix increment (operator++(int)
).
The answers given already in this thread are the ones I would recommend myself.
Not sure what you mean with "your baseclass is already a template".
PS. As I've said, this is not by the rules of Stack Overflow a good answer, but I just created an account, so I can't comment on other peoples answers.. Maybe someone can confirm and move this?