#include <string>
#include <iostream>
using namespace std;
class I1 {
public:
virtual int getI() const = 0;
virtual void setI(int i) = 0;
};
class I2 {
public:
virtual string getS() const = 0;
virtual void setS(string s) = 0;
};
class I3 {
public:
virtual float getF() const = 0;
virtual void setF(float f) = 0;
};
class I12 : virtual public I1, virtual public I2 {};
class I23 : virtual public I2, virtual public I3 {};
class I123 : virtual public I12, virtual public I23 {};
class C1 : virtual public I1 {
protected:
int i;
public:
int getI() const { return i; }
void setI(int i_) { i = i_; }
};
class C2 : virtual public I2 {
protected:
string s;
public:
string getS() const { return s; }
void setS(string s_) { s = s_; }
};
class C3 : virtual public I3 {
protected:
float f;
public:
float getF() const { return f; }
void setF(float f_) { f = f_; }
};
class C12 : public I12, public C1, public C2 {};
class C123 : public I123, public C1, public C2, public C3 {};
void f1(const I1& c1)
{
cout << "f1:\n";
cout << " getI: " << c1.getI() << endl;
}
void f2(const I12& c12)
{
cout << "f2:\n";
cout << " getI: " << c12.getI() << endl;
cout << " getS: " << c12.getS() << endl;
}
void f3(const I123& c23)
{
cout << "f3:\n";
cout << " getS: " << c23.getS() << endl;
cout << " getF: " << c23.getF() << endl;
}
void test()
{
C1 c1;
c1.setI(1);
f1(c1);
cout << "\n===== " << endl;
C12 c12;
c12.setI(12);
c12.setS("str12");
f1(c12);
f2(c12);
cout << "\n===== " << endl;
C123 c123;
c123.setI(123);
c123.setF(1.23f);
c123.setS("str123");
f1(c123);
f2(c123);
f3(c123);
cout << "\n===== " << endl;
}
int main()
{
test();
}