C ++通过类传递param?

时间:2013-07-05 00:25:35

标签: c++ class param

我正在写一个游戏;而不是把我的代码弄得一团糟,我真的很想做这样的事情。

这就是我现在的代码。

bool Verified[18] = { false }; // 18 for (18 clients in game)

比设置那个bool我显然会做

for(int Client;Client<18;Client++)
{
 Verified[Client] = false;
}

我想要实际做的是以下内容。

static class Clients
{
//Verified size is 18, for (18 clients max in game)
 bool Verified = the value sent by example below to client?

 //some functions i'd like to add later
}

我希望能够做到的是以下内容:

Clients[ClientIndex].Verified = false;
Clients[ClientIndex].SomeFunction_Call( < This param same as ClientIndex);

我不太了解c ++我知道;我失败了。但任何帮助都会很棒。

1 个答案:

答案 0 :(得分:1)

首先,c ++中没有static类。删除它。

现在你定义了课程后(不要忘记;在课程结束时

class Client {
public:
   bool var;
   void func (int i);
};

您需要创建一个数组(或矢量或任何东西)

Client clients[10];

然后,您可以像这样使用它:

    for (int i=0; i<10; i++) {
       clients[i].var = false;
    }

或者:

    for (int i=0; i<10; i++) {
        clients[i].func (i);
    }
相关问题