我一直在閱讀有關繼承,但我仍然沒有它100%的清楚,在這裏不用我的問題: 我有例如一類充滿東西:繼承行爲問題
class Something
{
public:
Something();
Something(int A);
Something(Something S);
~Something();
Something& operator=(const Something & s);
Something operator+(const Something & s) const;
// more methods ...
protected:
int A,B,C;
}
實現的所有方法某處,現在我只想要一個新類添加一個屬性,也許一個方法,但我仍然需要與SuperClass(構造函數,析構函數,方法,運算符)相同的行爲,所以我做這樣的事情:
class SomethingMore : public Something
{
public:
void OnlyMethodHere();
private:
int D;
}
但我得到的是這樣的:
undefined reference to SomethingMore::SomethingMore(int)
是否有AY告訴編譯器使用的一切就像是在超類或做我不得不在每一個孩子的方法的超類::()的方法?
對代碼的另一種觀察:使用上面的虛擬析構函數,因爲類有虛擬方法。 –
@ vine'th:我在這裏看不到任何虛擬功能。 –
btw,'Something(Something S);'是錯的。我不知道它是否編譯。即使編譯,程序也會因StackOverflow而崩潰! :) – balki