C++相談室 part30
■ このスレッドは過去ログ倉庫に格納されています
0320デフォルトの名無しさん
NGNGstruct A
{
virtual void Foo1(void) { std::cout << "A" << std::endl; }
void Foo2(void) { Foo1(); }
};
struct B : public A
{
void Foo1(void) { std::cout << "B" << std::endl; }
};
struct C : public B
{
void Foo1(void) {
std::cout << "C" << std::endl;
B::Foo2(); }
};
int main( int argc, char *argv[] )
{
struct C test;
test.Foo1();
return 0;
}
これを実行したときに、「CCCCCCCC・・・」と永遠に続いてしまいます。
test.Foo1()を実行ときに「CB」と表示されて終了して欲しいのですが、何か良い手段はないでしょうか?
(B::Foo2()を実行したときに B::Foo1() が呼び出されて欲しい。)
ちなみに、「B::Foo2()」を「B *cls = (B *)this; cls->Foo2();」にしても結果は同じでした。
■ このスレッドは過去ログ倉庫に格納されています