Similar to this question, how do I test that a class Impl
publicly inherits from a template class BaseTempl
(i.e. class Impl : public BaseTempl< ... >{ ... };
), without specifying the template arguments?
Different from the aforementioned question, however, I would like the test to still compile (and return false) if the inheritance is not public.
Ideally, the code would allow me to do something like this:
class alpha : public BaseTempl< int >{};
class bravo : BaseTempl< int >{};
class charlie{};
class delta : public BaseTempl< int >, public charlie {};
class echo : public delta {};
int main(){
publicly_inherits_from < alpha, BaseTempl > (); // true
publicly_inherits_from < bravo, BaseTempl > (); // false
publicly_inherits_from < charlie, BaseTempl > (); // false
publicly_inherits_from < delta, BaseTempl > (); // true
publicly_inherits_from < echo, BaseTempl > (); // true
}
The answer from the linked question gives the following error when I attempt to compile the above code:
error: ‘BaseTempl<int>’ is an inaccessible base of ‘bravo’
Aucun commentaire:
Enregistrer un commentaire