I
iuweriur
A few questions on the curiously recurring template pattern:
This page:
http://c2.com/cgi/wiki?CuriouslyRecurringTemplate
this part:
template<typename T> struct ArithmeticType
{
T operator + (const T& other) const
{
T result(*this); // <--------- THIS LINE
result += other;
return result;
}
// etc.
};
In the above marked line, how comes that one doesn't need any type of
cast from *this to const T& ?
And if the cast is needed, what type of cast would you use?
I suppose that the reinterpret_cast would not be portable (in theory, or
also in practice?) and anyway does not handle cases with MI, and the
dynamic_cast is slow and works only on polimorphic types, right?
Another question on this page:
http://www.informit.com/articles/article.asp?p=31473&seqNum=3
At the end there is written:
----
In general, CRTP is useful to factor out implementations of interfaces
that can only be member functions (for example, constructor,
destructors, and subscript operators).
----
For the subscript I can maybe understand, but how can you do it for
constructors and destructors?
Thank you
iuweriur
This page:
http://c2.com/cgi/wiki?CuriouslyRecurringTemplate
this part:
template<typename T> struct ArithmeticType
{
T operator + (const T& other) const
{
T result(*this); // <--------- THIS LINE
result += other;
return result;
}
// etc.
};
In the above marked line, how comes that one doesn't need any type of
cast from *this to const T& ?
And if the cast is needed, what type of cast would you use?
I suppose that the reinterpret_cast would not be portable (in theory, or
also in practice?) and anyway does not handle cases with MI, and the
dynamic_cast is slow and works only on polimorphic types, right?
Another question on this page:
http://www.informit.com/articles/article.asp?p=31473&seqNum=3
At the end there is written:
----
In general, CRTP is useful to factor out implementations of interfaces
that can only be member functions (for example, constructor,
destructors, and subscript operators).
----
For the subscript I can maybe understand, but how can you do it for
constructors and destructors?
Thank you
iuweriur