我希望用用户非常复杂的初始条件进行模拟。我正在写class A它的成员变量需要在运行之前由用户初始化A.Solve()以获得存储在文件中的结果。初始化相当复杂,需要几个在初始化后不再需要的临时数据结构。因此,我编写了另一个名为class Initializer的类,它存储对class A. 我的代码将如下所示:
 class A {
   friend class Initializer;
   private:
     // member variables storing the state of the system
   public:
     void Solve();
     ...
 };
 class Initializer {
   private:
     A& a
     // Other data structures used in the initialization
     ...
   public:
     // functions called by the user to set up for the initialization
     ...
     Initialize(); // after this is called, a will be ready to solve
 };
 int main(...) {
   A a;
   Initializer init(a);
   // call functions on init to initialize the system
   ...
   init.Initialize();
   a.Solve();
   return 0;
 }
但似乎数据结构init将存在于整个程序的堆栈中。为了防止这种情况,可以这样做:
  A a;
  Initializer *init = new Initializer(a);
  ....
  init.Initialize();
  delete init;
  a.Solve();
或者这看起来没有必要,我应该把所有的东西都包含在里面class A吗?