與this question類似,我如何測試類Impl
是否從模板類BaseTempl
(即class Impl : public BaseTempl<...>{ ... };
)(沒有指定模板參數)公開繼承?檢查C++類是否從模板類公開繼承匿名參數
但是,與上述問題不同,如果繼承不公開,我希望測試仍然能夠編譯(並返回false)。
理想情況下,代碼會允許我做這樣的事情:
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
}
從鏈接的問題的答案提供了以下錯誤,當我試圖編譯上面的代碼:
error: ‘BaseTempl<int>’ is an inaccessible base of ‘bravo’
的可能的複製[性狀檢查模板類的某些特化是否是特定類的基類](http://stackoverflow.com/questions/25845536/trait-to-check-if-some-specialization-of-template-class-is-base-類OF-特別) – Orient