遺憾的是,似乎任何類型的多重繼承的是不支持,即使它只是一個「接口」,它統一了其他幾個「接口」,如:
struct IA { virtual void a() = 0; };
struct IB { virtual void b() = 0; };
struct IC : public IA, public IB {};
fakeit::Mock<IC> mock; // error :(
(該檢查是用做std::is_simple_inheritance_layout<T>
)
我沒有,但是,找到一點的辦法解決這個問題,至少對於簡單的場景:
class MockC : public IC {
public:
MockC(IA& a, IB& b) : m_a(a), m_b(b) {}
void a() override { return m_a.a(); };
void b() override { return m_b.b(); };
private:
IA& m_a;
IB& m_b;
};
fakeit::Mock<IA> mockA;
fakeit::Mock<IB> mockB;
MockC mockC(mockA.get(), mockB.get());
// Use mockA and mockB to set up the mock behavior the way you want it.
// Just make sure not to use mockC after they go out of scope!