C++简单的子类继承父类访问父类的成员函数和成员变量
程序员文章站
2022-07-15 21:04:46
...
#include<iostream>
using namespace std;
class A
{
public:
A()
{
p = 1;
}
void Print(int &a)
{
++a;
cout<<"a == "<<a<<endl;
}
~A()
{
p = 0;
}
int p;
};
class B:public A
{
public:
B()
{
a = 1;
cout<<"p == "<<A::p<<endl;
}
~B()
{
}
void Cout()
{
Print(a);
Cout(a);
cout<<"aaa"<<endl;
}
void Cout(int &b)
{
++b;
cout<<"ARGS == "<<b<<endl;
}
int a;
};
int main()
{
B c;
int a = 1;
c.Cout();
return 0;
}