How to insert custom class item to map C++ -


i have class, how can add 1 object of class map, , find id?

class code:

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 add client map , how can find id? } 

i tried many example codes not custom class didn't work. thanks!

for adding client key=10:

clienttable[10] = client(1, id, 1); 

for find element key=10:

std::map<int, client>::iterator = clienttable.find(10); if (it != clienttable.end()) {     int key = it->first;     client c = it->second; } 

you can use:

client c = clienttable[10]; 

but calling operator[] not const. so, not want use if want find element.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -