Get the instance Name from a pointer?

How can I get the NAME of an instance by a pointer to the object ?

I can do this:


and I get the temperatur on the LCD screen - it works nicely.

Now I need to know WHO the activePump is - by it's instance name - but how ?

You can't. All variable names (including object names) are lost after the code is compiled and linked.

You could provide an instance function that returns an ID.

add class member called name, set it on object init. add getName() method to return name

If activePump has a method returning its name then use that…

Tell the object its name and then ask the object for its name.

As the others said you can't "get" the "name" unless you initialize it into the instance itself. If you didn't create the class yourself you could inherit from it and your derived class could have the name in it.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.