我正在写一个游戏;与其把我的代码弄得一团糟,我真的很想做这样的事情。
这就是我的代码现在的样子。
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++的了解不多;我失败了。但任何帮助都会很棒。
最佳答案
首先,C++ 中没有static
类这样的东西。删除它。
现在在您定义类之后(不要忘记;在类的末尾)
class Client {
public:
bool var;
void func (int i);
};
你需要创建一个数组(或 vector 或任何东西)
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);
}
关于C++ 通过类传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17479586/