What I am trying to do is have some classes inherit form an extention class. The thing is the extention class has to know which class it is extending.
This can simply be achieved like this:
template<typename Self>
class Extention
{
public:
void check() const
{
std::cout << "Extention is valid: "
<< std::boolalpha
<< std::is_base_of<Extention, Self>::value
<< std::endl;
}
};
class Foo : public Extention<Foo> {};
class Bar : public Extention<void> {};
The Foo and Bar class show good, and bad usage of the extention.
Foo().check(); → Extention is valid: true
Bar().check(); → Extention is valid: false
I would like to check the validity of the template during compilation, which brought me to write
template<typename Self>
class Extention
{
static_assert(std::is_base_of<Extention, Self>::value);
};
However, gcc tels me this static_assert is wrong as class Foo has incomplete type.
What am I doing wrong ?
Edit: I'm using -std=c++17, error is not the lack of error message in the static_assert