Hi there, I'm still fairly new to C++ and trying to get used to a more object oriented programming approach. However I'm struggling with how (or if it's even possible in c++) to implement this:
The concept
--------------------------
I have a program that creates an object of a given class every time a certain event happens. These objects contain functions for handling messages that are passed to them. The main program contains a message handling procedure to intercept these messages, identify which object they belong to, and pass the commands + arguments to the required function within the object.
--------------------------
The problem I have is in identifying each object after it has been created. My function for creating objects is just using new and has the object's constructor set everything up.
I could create a pointer to that object's memory address when it is created, but then I am just passing the problem from the object itself to the pointer - how do I uniquely identify each object without explicitly naming either the object itself or a pointer to it?
I have looked around for a way to procedurally generate the names as they are created, and played with some code to try and use the value of a variable or the return value of a function as the name for a new object / pointer but I couldn't find a solution. Is there a way to generate names this way?
My other option would be to build a database where on creation the object assigns itself an identifier internally, and passes this to a database alongside its memory location, and the message procedure looks in this database, but this seems sloppy.
Any guidance would be much appreciated!