在C ++的类函数中创建类的实例?

时间:2016-09-10 06:53:25

标签: c++ class instance simulation

我试图创建各种有机体模拟,并且每当男性和女性有机体彼此相邻时,所需功能之一就会创建一个新类实例。所以我基本上需要这样的东西:

class foo
{
  int a;
};

void double_foo
{
//Create new instance of foo
//First time its called, foo instance_1;
//Second time its called, foo instance_2;
//...
}
void define_foo
{
//instance_1.a = random number
//instance_2.a = random number
...
//instance_n = random number
}

1 个答案:

答案 0 :(得分:1)

创建新生物体的功能应该是这样的(我原始代码的复制粘贴部分):

set contour; unset surface
set table $datatable
splot dataf
unset table

你需要在你的主体中称呼它并将生物体与所有其他生物体一起储存:

plot for [i=0:5] $datatable index i, f(x)