6
基本クラスをメンバーのように融合させることは可能ですか?基本クラスを融合することは可能ですか?
は、まず、これはドキュメントの例で、サイド・バイ・サイドの新しいケース付き:私は???
に沿って置くべきこと
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
struct employee{
std::string name;
int age;
};
BOOST_FUSION_ADAPT_STRUCT(
employee,
(std::string, name)
(int, age))
struct employee2 : std::string{
int age;
};
BOOST_FUSION_ADAPT_STRUCT(
employee2,
(std::string, name) ???
(int, age))
int main(){}
。
私が見つけた唯一の解決策はこれを行うことですが、1)すべてのメンバーをゲッターとセッターの機能にする必要があります。2)過度のようです。
#include <boost/fusion/adapted/adt/adapt_adt.hpp>
struct employee2 : std::string{
int age;
void set_base(std::string const& age_){std::string::operator=(age_);}
std::string const& get_base() const{return static_cast<std::string const&>(*this);}
void set_age(int const& age_){age = age_;}
int const& get_age() const{return age;}
};
BOOST_FUSION_ADAPT_ADT(
employee2,
(std::string, std::string, obj.get_base(), obj.set_base(val))
(int, int, obj.get_age(), obj.set_age(val))
)