問題2:クラスの相互参照
| この問題を解くためには… |
| → 応用編第2日目参照 |
|---|
probex2-1.(難易度:★)
以下のプログラムをビルドが通り、期待される実行結果が得られるように変更しなさい。
bar.h
#ifndef _BAR_H_
#define _BAR_H_
class Foo;
class Bar{
public:
void func1(Foo* pFoo);
void func2();
};
#endif // _BAR_H_
#ifndef _FOO_H_
#define _FOO_H_
class Bar;
class Foo{
public:
void hoge();
void fuga(Bar* pBar);
};
#endif // _FOO_H_
#include "bar.h"
#include <iostream>
using namespace std;
void Bar::func1(Foo* pFoo)
{
pFoo->hoge();
}
void Bar::func2()
{
cout << "Bar::func2" << endl;
}
#include "foo.h"
#include <iostream>
using namespace std;
void Foo::hoge(){
cout << "Foo::hoge()" << endl;
}
void Foo::fuga(Bar* pBar){
cout << "Foo::fuga()" << endl;
pBar->func2();
}
#include "foo.h"
#include "bar.h"
#include <iostream>
using namespace std;
void main(){
Foo* pFoo;
Bar* pBar;
}
Foo::hoge()
Bar::func2()
Foo::fuga()
Bar::func2()
Foo::hoge()
Bar::func2()
Foo::fuga()
Bar::func2()
Foo::hoge()









