具有模板和可见性的C 继承
c++ Inheritance with templates and visibility
我不明白ATT与模板的所有继承。
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() {
}
};
有关详细的讨论,请参阅为什么受保护的构造函数提出错误此代码?
相关文章:
- 如何更改唯一指针向量的可见性
- 当指向对象的指针作为参数传递给 std::thread 时,内存可见性
- 限制静态库中符号的可见性 (MSVC/Visual C++)
- 班级成员可见性C++
- 内联模板函数的可见性
- Clang 是否可以在使用可见性属性时生成导入库(不带 __declspec(dllexport))?
- std::mutex 的发布-获取可见性保证是否仅适用于关键部分?
- 符号可见性和 gcc 警告
- C++/libscreen 无法更新可见性
- 在 C++11 线程中,std::mutex 对内存可见性有什么保证?
- C++继承构造函数的可见性
- CRTP - 嵌套叶类类型的可见性
- C++模板 - 实例之间的通用操作和成员可见性
- 放松的订单和线程间可见性
- GCC 6.x警告有关Lambda可见性
- 未直接继承的基模板类成员的可见性
- 具有模板和可见性的C 继承
- 继承类中嵌套类的可见性
- 继承构造函数、默认构造函数和可见性
- 可变模板混合继承的可见性规则