#include<string>#include<string_view>classPerson{private:std::stringm_name{};intm_age{};public:Person(std::string_viewname,intage):m_name{name},m_age{age}{}conststd::string&getName()const{returnm_name;}intgetAge()const{returnm_age;}};classEmployee{private:std::stringm_employer{};doublem_wage{};public:Employee(std::string_viewemployer,doublewage):m_employer{employer},m_wage{wage}{}conststd::string&getEmployer()const{returnm_employer;}doublegetWage()const{returnm_wage;}};// Teacher public 继承 Person 和 Employee
classTeacher:publicPerson,publicEmployee{private:intm_teachesGrade{};public:Teacher(std::string_viewname,intage,std::string_viewemployer,doublewage,intteachesGrade):Person{name,age},Employee{employer,wage},m_teachesGrade{teachesGrade}{}};intmain(){Teachert{"Mary",45,"Boo",14.3,8};return0;}
#include<string>structPoint2D{intx{};inty{};};classBox// 混合类型 Box
{public:voidsetTopLeft(Point2Dpoint){m_topLeft=point;}voidsetBottomRight(Point2Dpoint){m_bottomRight=point;}private:Point2Dm_topLeft{};Point2Dm_bottomRight{};};classLabel// 混合类型 Label
{public:voidsetText(conststd::string_viewstr){m_text=str;}voidsetFontSize(intfontSize){m_fontSize=fontSize;}private:std::stringm_text{};intm_fontSize{};};classTooltip// 混合类型 Tooltip
{public:voidsetText(conststd::string_viewstr){m_text=str;}private:std::stringm_text{};};classButton:publicBox,publicLabel,publicTooltip{};// Button 使用三个混合类型
intmain(){Buttonbutton{};button.Box::setTopLeft({1,1});button.Box::setBottomRight({10,10});button.Label::setText("Submit");button.Label::setFontSize(6);button.Tooltip::setText("Submit the form to the server");}