Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Pointer as a key in a hashtable

Are there any problems using pointers as hashtable keys during program run? (no need to store to disk and use it later as that causes obvious problems)

There are many circumstances where I need to quickly know whether an object belongs to some object manager. A quick way to check it is to store every object in an object manager in a hashtable where the object's pointer is the key to the actual object: E.g, HashTable

like image 875
bittersoon Avatar asked Jan 17 '11 12:01

bittersoon


1 Answers

No, there are no problems. It's just like storing an int.

A pointer has got a value that doesn't change and that uniquely identify a resource.

There of course be problems if you don't use well your pointers, but this is another, uncorrelated thing.

like image 182
peoro Avatar answered Sep 20 '22 22:09

peoro