Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;具有模板和可见性的继承_C++_Templates_Inheritance_Visibility - Fatal编程技术网

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

C++ c++;具有模板和可见性的继承,c++,templates,inheritance,visibility,C++,Templates,Inheritance,Visibility,我不理解所有的模板继承 template <typename T> class Mere { protected: Mere(); }; class Fille2 : public Mere<int> { protected: Fille2(){ Mere(); } }; int main(int argc, char** argv) { return 0; } 模板 纯粹阶级 { 受保护的: 仅仅(

我不理解所有的模板继承

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

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


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

    return 0;
}
模板
纯粹阶级
{ 
受保护的:
仅仅();
}; 
第2类:公共场所
{ 
受保护的:
Fille2(){
仅仅();
}
}; 
int main(int argc,字符**argv){
返回0;
}
为什么我会有这个错误

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

当我把“仅仅()”公之于众时,一切都会起作用吗?我的类不能有“受保护”的函数“仅仅”?为什么?

是的,您可以调用基类构造函数,即使它受
保护。以下是正确的语法:

class Fille2 : public Mere<int>
{ 
protected:
    Fille2(): Mere() {
    }
}; 
class Fille2:公共文件
{ 
受保护的:
Fille2():仅仅(){
}
}; 

详细讨论,参见

这不是您如何调用C++中父类的构造函数…看看如何做到这一点