指针/引用作为类成员vs传递作为参数

时间:2014-05-24 11:27:58

标签: c++ class pointers structure

C ++专家的快速提问。 :)

我有一个监听器类,它检查每一帧的按键,并根据按下的键,将不同的命令传递给一个向量,该向量依次在每个帧的开头执行。

我的问题是,通过将命令容器的引用/指针保持为每帧(大约30 FPS)传递给更新函数的参数,或者我应该将指针保持为成员,我会获得任何东西吗?听众类?

我想记得有人告诉我第一种方法因为代码隔离而更好,但这是真的吗?

编辑:

class Listener
{
void update(std::vector<Command>& vCommands); //This function is called about 30 times every second from the main loop      of the program
}

VS这个

class Listener
{
void update()
std::vector<Command>* vCommands; //Keeping a constant reference to the container instead.
}

0 个答案:

没有答案