c++继承另一命名空间的类
2021-07-08 本文已影响0人
一路向后
1.头文件
#include <iostream>
namespace A {
class A {
public:
void run();
};
}
namespace B {
class B : public A::A {
public:
void save();
};
}
2.cpp文件
#include <cstdio>
#include "test.h"
using namespace std;
void A::A::run()
{
printf("A is running!\n");
}
void B::B::save()
{
printf("B is saving!\n");
}
int main()
{
A::A a;
B::B b;
a.run();
b.run();
b.save();
return 0;
}
3.编译源码
$ g++ -o test test.cpp
4.运行及其结果
$ ./test
A is running!
A is running!
B is saving!