私のプログラムはクラッシュの原因を示すことなく、突然停止します。私がしようとしているのは、(継承を介して)派生クラスのクラスメンバーを使用することです逆:実行時にプログラムがクラッシュする
#include <iostream>
using namespace std;
class Base
{
public:
void attribBase();
};
class Derived : public Base
{
public:
void attribDerived();
};
void Base::attribBase()
}
Derived d;
d.attribDerived();
}
void Derived::attribDerived()
{
Base b;
b.attribBase();
}
int main()
{
Base b;
Derived d;
b.attribBase();
d.attribDerived();
return 0;
}
無限の再帰があります。 'attribDerived()'は 'attribDerived()'を呼び出す 'attribBase()'を呼び出します。 – Barmar
'b.attribBase();'作成する 'b.attribBase();'を呼び出すBaseオブジェクトを作成する 'd.attribDerived();'を呼び出すDerivedオブジェクトを作成します....無限再帰 – Amadeus
本当にすべきですコードをインデントします。編集ウィンドウの左の余白に対してフラッシュされたすべてを書き込むときに、クラスまたは関数の開始位置と終了位置を確認するのは難しいです。 – PaulMcKenzie