袁辉勇 5=30 继承 2== private: int x;

2==  private:   int x;

#include <iostream>
using namespace std;
class test
{
  private:      int x;
  public :       int y;
  protected :    int z;
};

class test2:  public  test
{              };                                                                      没有成员

int main(   )
    test2  t;
    
       cout << t.x<<endl;
         cout << t.y<<endl;
     cout << t.z<<endl;
    
}








#include <iostream>
using namespace std;
class test
{
  private:      int x;
  public :       int y;
  protected :    int z;
};

class test2:  public  test
{       public:      void show( )  {  cout<<x;    }                };                                // 成员

int main(   )
    test2  t;
    
       cout << t.x<<endl;
         cout << t.y<<endl;
     cout << t.z<<endl;
    
}





保护继承   更差劲

C++ 文章被收录于专栏

C++谭浩强 冯博强 贾应知 袁辉勇

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务