#include <iostream>
#include <thread>
#include <math.h>
#include <vector>
#include <queue>
class A{
public:
A(int i){ a_ = i;}
int a_;
};
class B : public A{
public:
B(int j) : A(3){b_ = j;}
int b_;
};
class C : public B{
public:
C(int k) : B(4){c_ = k;}
int c_;
};
int main()
{
//定义A类 构造函数赋值a5
A test_a(5);
std::cout << "test_a.a_ = " << test_a.a_ << std::endl;
//定义B类 构造函数赋值b1 B继承A赋值a3
B test_b(1);
std::cout << "test_b.a_ = " << test_b.a_ << std::endl;
std::cout << "test_b.b_ = " << test_b.b_ << std::endl;
//定义C类 构造函数赋值c2 C继承B赋值b4 B继承A赋值a3
C test_c(2);
std::cout << "test_c.a_ = " << test_c.a_ << std::endl;
std::cout << "test_c.b_ = " << test_c.b_ << std::endl;
std::cout << "test_c.c_ = " << test_c.c_ << std::endl;
}
最终结果为
test_a.a_ = 5
test_b.a_ = 3
test_b.b_ = 1
test_c.a_ = 3
test_c.b_ = 4
test_c.c_ = 2