Suppose I have the following classes:
template <typename SELF>
class Base {
protected:
template <int X>
void foo();
};
class Child : public Base<Child> {
public:
Child() {
//I want this to throw a static assertion failure
foo<10>();
}
~Child() {
//Should also static assert here
}
};
Is there any way I make the compiler throw a compile-time assertion failure if the templated member method foo() is called within the constructor or destructor? In other words, I want to prevent, at compile time, the method from being called within the constructor or destructor.
Please don't ask why foo is a template; this is just a simplified example of a more complex project.