⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acc_decl.cpp

📁 不错书对C++/C程序员很有用的大家不要错过.
💻 CPP
字号:
#include <iostream.h>

class base 
{
   int i;         // private in base class
 public:
   int j, k;
   void seti(int x) {i = x;}
   int geti(void) {return i;}
 };

class derived : private base 
{
 public:
                  // The next statements override the private inheritance.
   base::j;       // makes j public again
   base::seti;    // makes seti() public
   base::geti;    // makes geti() public
   // base::i; is an illegal statement, you cannot promote access.
   int a;
 };

void main(void)
 {
   derived object;

   //object.i = 10;  Illegal statement; i is private to base.
   object.j = 20; // legal because j is public

   //object.k = 30; Illegal because k is private to derived
   object.a = 40;
   object.seti(10);
   cout << object.geti() << ", " << object.j << ", " << object.a;
 }

 


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -