这样可以吗?即时通讯基本上用一个封装了所有游戏实体和逻辑的类来代替对引用全局变量的单个函数的调用,下面是我想如何在main中调用新类,只是想知道在这方面一般的C++大师共识是什么。C++设计模式
class thingy
{
public:
thingy()
{
loop();
}
void loop()
{
while(true)
{
//do stuff
//if (something)
//break out
}
}
};
int main (int argc, char * const argv[])
{
thingy();
return 0;
}
呃,为什么不把'loop'作为自己的函数呢? –
而不是主要在阳光下做所有事情你做了一个封装另一个函数的类,它在构造函数中调用了太阳下的所有东西。我不会称之为设计模式。 – AJG85
这是什么问题? –