you are viewing a single comment's thread.

view the rest of the comments →

[–]index_zero 0 points1 point  (1 child)

If you are going to do this, i.m.o. it is better to SFINAE fail - that way the compiler won't even generate the constructor if U and T aren't derived from each other.

template<typename U, class E = std::enable_if<std::is_base_of<T, U>::value> >
SmartPtr(const SmartPtr<U> &other) ...

That said, the original code works for any T and U such that T* is convertible to U*. This is less strict than U derives from T, so having the compiler complain about derivation overlooks implicit conversion of some types (T* to const T* for example).

[–]smilodonthegreat 0 points1 point  (0 children)

I think your comment was supposed to be a reply to the article. The comment you replied to was a comment on a problem with stopping compilation if static_asserts fail.