【发布时间】:2012-06-05 19:09:28
【问题描述】:
我有一个类,如何将这个类的一个对象添加到映射中,并通过 id 找到它?
类代码:
class Client {
int FileDescriptor, Id, cryptcode;
unsigned char CustomData[256];
void PrepareClient()
{
// init code
}
public:
AnticheatClient (int fd, int id, int crypt_code)
{
FileDescriptor = fd;
Id = id;
cryptcode = crypt_code;
PrepareCrypt();
}
void OwnCryptEncrypt(unsigned char* data, int len)
{
//...
}
void OwnCryptDecrypt(unsigned char* data, int len)
{
//...
}
};
std::map<int, Client> ClientTable;
int main()
{
int id = 1;
Client c(1, id, 1);
// how can i add this client to map and how can i find it by id?
}
我尝试了很多示例代码,但没有使用自定义类,因此它们不起作用。 谢谢!
【问题讨论】:
-
“他们没有工作”是什么意思?
-
StackOverflow is not a Language Tutorial. 要获得经过同行评审的优秀学习资源,请查看The Definitive C++ Book Guide and List 和我们的C++-FAQ Tag
-
请复制粘贴您的错误信息。还有你在 main 中尝试的代码。