c++ - 继承问题

标签 c++ class inheritance

class Base
{
   private:
      int var;
};

class Child : protected Base
{
   void someFunc()
   {
      var = 5; // Error: Base::var is private
   }
};

有什么问题吗?

最佳答案

试试这个:

class Base
{
   protected:
      int var;
};

参见 this reference了解 C++ 中 private、protected 和 public 之间的区别。

关于c++ - 继承问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3980310/

相关文章:

python - 为战斗模拟器生成随机数

python - 检查函数是否包含 pass

c++ - C++中对象的继承和双端队列

c++ - std::vector 析构函数中的段错误

c++ - 无法在 ubuntu 20.04 中安装 g++

c++ - C++ 中的动态函数参数,可能吗?

class - 如何在 Object Pascal "class of interface"(或 "interface of interface")类型中创建

c++ - CUDA 内核调用阻塞?

inheritance - JPA TABLE_PER_CLASS继承: How to only SELECT superclass entries?

java - 使用接口(interface)和枚举的潜在类型