繁体   English   中英

c ++具有模板和可见性的继承

[英]c++ Inheritance with templates and visibility

我不明白所有继承模板..

template <typename T> 
class Mere 
{ 
protected:
    Mere();
}; 

class Fille2 : public Mere<int>
{ 
protected:
    Fille2(){
        Mere();
    }
}; 


int main(int argc, char** argv) {

    return 0;
}

为什么我有这个错误?

main.cpp:22:5: error: 'Mere<T>::Mere() [with T = int]' is protected
Mere();

当我把“Mere()”公之于众时,一切都有效吗? 我不能为我的班级“仅仅”提供“保护”功能吗? 为什么?

是的,您可以调用基类构造函数,即使它protected 这是正确的语法:

class Fille2 : public Mere<int>
{ 
protected:
    Fille2(): Mere() {
    }
}; 

有关详细讨论,请参阅为什么受保护的构造函数引发此代码的错误?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM