qq_45813272
qq_45813272
2021-01-20 19:06

c++ 公有继承的程序改错题 请大佬指点

  • c++

#include<iostream>
using namespace std;
class Base
{int a;
protected:
int b;
public:
Base(int x,int y){a=x;b=y;}
void displayA()
{cout<<a<<endl;}
};
class Derived:public Base
{int d;
public:
Derived(int x,int y,int z)
{d=z;}
void displayB()
{cout<<a;
cout<<b;
cout<<d;}
};
int main()
{Derived t1(10,20,30);
cout<<t1.b<<endl;
t1.displayA();
t1.displayB();}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答