Thursday, 22 August 2013

c++: even more curiously recurring template pattern

c++: even more curiously recurring template pattern

and thanks for your help. Probably everyone knows CRTP in C++ and its pros
and cons. Suppose I have BaseObject, Object and Int classes, where Object
is a template class used to perform CRTP. In Object there are defined
operators like operator signed short() const, which all return result from
virtual function Int cast_int() const, which is later proceeded to signed
signed short type, using overloaded Int::operator signed short() const
function. everything goes well when I derive from class like this: class
Child: public Object<Child>. What if I want to derive from Int? Is there a
way to.show that I want to use not Int::cast_int() const, but
Child::cast_int() const to cast to Int and then to signed short?
If it will be necessary, I'll post the code. I've already tried virtual
operator signed short() const { return this->cast_int(); } variant, but
all derived from Int classes act as if they cast from Int, not from Child.
Do I always need to explicitly derive like class Child: public
Object<Child>, public Int>? I can't use C++11, if it plays any role.
Thanks in advance!

No comments:

Post a Comment