使用boost::mpl::inherit_linearly的相关用法测试程序(C/C++)
#include
#include <boost/mpl/vector.hpp>
#include <boost/mpl/inherit_linearly.hpp>
#include <boost/mpl/inherit.hpp>
using namespace boost::mpl;
// 定义基类
struct Base {
virtual void print() = 0;
};
// 定义派生类A
struct A : Base {
void print() {
std::cout << “This is class A.” << std::endl;
}
};
// 定义派生类B
struct B : Base {
void print() {
std::cout << “This is class B.” << std::endl;
}
};
// 定义派生类C
struct C : Base {
void print() {
std::cout << “This is class C.” << std::endl;
}
};
// 使用inherit_linearly实现多重继承
typedef vector<A, B, C> ClassList;
typedef inherit_linearly<ClassList, inherit<arg<1>, arg<2&