More specifically, let's say I have a class template with parameters A
and B
, and I would like to have a compiler error (when the template is being instantiated) if B is not derived from A.
template<class A, class B>
class Foo
{
// static_assert(B is derived from A)
};
This has been asked so very many times before, but it's so simple I'll post the solution again:
~Foo()
{
A* p = (B*)0; // B is required to be a subtype of A
}
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