我有一个类,如何将这个类的一个对象添加到映射中,并通过 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?
}
我尝试了很多示例代码,但没有使用自定义类,所以它们不起作用。谢谢!