シミュレーションプログラムをセットアップしようとしています。シミュレーションはいくつかのステップで実行され、シミュレーション クラスはさまざまなクラスの ::step() を呼び出す必要があります。そのうちの 1 つが _experiment クラスです。
実験クラスにはシミュレーションクラスが必要であり、シミュレーションクラスは実験クラスが何であるかを知る必要があるため、これを機能させることができません。したがって、それらは循環依存です。前方宣言を使用して解決しようとしましたが、前方宣言されたクラスのメソッドにアクセスできません。それでは、前方宣言のポイントは何ですか?誰でも私を助けることができますか?ありがとう!
main.cpp
int main()
{
_experiment experiment;
}
実験.cpp:
#include "experiment.h"
_experiment::experiment()
{
_simulation simulation;
simulation.experiment = this;
simulation.start();
}
void _experiment::step()
{
//Apply forces to simulation
}
実験.h:
#include "simulation.h"
class _experiment {
public:
void step()
};
シミュレーション.cpp:
#include "simulation.h"
void _simulation::run()
{
//Run simulation for 1000 steps
for(int i = 0; i < 1000; i++)
{
experiment->step() //Calculate forces. Doesnt work (cant use member functions of forward declared classes. How to work around this?
//Calculate motion
}
}
シミュレーション.h:
class _experiment; //Forward declaration
class _simulation {
public:
_experiment* experiment
void run();
};