By what have I to replace the missing line to have this CRTP solution working ?
template<class Crtp> class Base
{
public:
inline Crtp& operator=(const Base<Crtp>& rhs)
{
for (unsigned int i = 0; i < const_size; ++i) {
_data[i] = rhs._data[i];
}
return /* SOMETHING HERE BUT WHAT ? */
}
protected:
static const unsigned int const_size = 10;
double _data[const_size];
};
class Derived : public Base<Derived>
{
};
Other question : does the solution you will provide has a cost at running time (compared to the solution where the operator is directly implemented in the derived class) ?
Thank you very much.
return static_cast<Crtp&>(*this);
This has no cost at run time (but you might want to protect the constructor of Base).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With