zoukankan      html  css  js  c++  java
  • 隔断继承的疑惑-待问

      #include<iostream>
      2 #include<string>
      3 using namespace std;
      4 class parent{
      5 protected:
      6         int m_a;
      7         int m_b;
      8 public:
      9         int m_c;
     10         void set(int a,int b,int c){
     11                 m_a = a;
     12                 m_b = b;
     13                 m_c = c;
     14         }
     15 };
     16 class child_A:public parent{
     17 public:
     18         void print(){
     19                 cout << "m_a=" << m_a << endl;
     20                 cout << "m_b=" << m_b << endl;
     21                 cout << "m_c=" << m_c << endl;
     22         }
     23 };
     24 class child_B:protected parent{
     25 public:
     26         void print(){
     27                 cout << "m_a=" << m_a << endl;
     28                 cout << "m_b=" << m_b << endl;
     29                 cout << "m_c=" << m_c << endl;
    30         }
     31 };
     32 class child_C:private parent{
     33 public:
     34         void print(){
     35                 cout << "m_a=" << m_a << endl;
     36                 cout << "m_b=" << m_b << endl;
     37                 cout << "m_c=" << m_c << endl;
     38         }
     39 
     40 };
     41 class child_D:public child_C{
     42 };
     43 int main(){
     44         //child_A a;//public继承
     45         //child_B b;//protected 继承
     46         //child_C c;//private继承
     47         //a.m_c = 100;//100
     48         //b.m_c = 100;//100
     49         //c.m_c = 100;
     50         //a.print();
     51         //b.print();
     52         //c.print();
     53         //cout << endl;
     54         //a.set(1,1,1);
     55         //b.set(2,2,2);
     56         //c.set(3,3,3);
    57         child_D d;
     58         d.print();
     59         d.set(1,2,3);
     60         return 0;
     61 }
  • 相关阅读:
    Python 更新pip报错:Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问
    Vs code 配置(1)-win10
    博客园主题--sukura
    log4j
    安装ant问题
    freemarker string= null
    学习随想
    j2ee学习资料收集
    eclipse + marven
    好文mark
  • 原文地址:https://www.cnblogs.com/DXGG-Bond/p/11919826.html
Copyright © 2011-2022 走看看