我有一個簡單的抽象類(比如說A)和繼承它的類(比如C)。「無法實例化抽象類」錯誤
class C : A
問題是第二個(C)包含我需要在另一個類中的代碼;我認爲將這部分代碼拆分爲單獨的類(B)並將其從我需要的類派生出來是很好的。
B(的代碼共享部分)>> C(目標)< < A(對於C抽象基)
它是所有行 - 除了在基類(A)聲明爲抽象的功能之一 定義於B,而非C。這導致我的錯誤,我想。 ,我在尋找解決方案...
class A // a base class i need to derive from
{
// ...
public: virtual bool Get() const;
// ...
};
class B // only contains definition for get()
{
public:
bool Get() const { return false; }
};
class C : public B, public A // firstly derive from B, than from A.. ??
{
// so Get(), required by A is defined in B, which C derives from ...
// and i cant derive from A because of that... I can't do that anyway?
};
我希望我描述正確的..
但是'A'類不是抽象的嗎? –
A是抽象的,C是我需要從A中推導出來的。但A抽象標記的一些定義是在B中,而不是C. – Loryan55
這不是重複的問題。大聲笑 – Loryan55