ksor
August 9, 2021, 8:10pm
1
How can I get the NAME of an instance by a pointer to the object ?
I can do this:
lcd.print(activePump->getTemperature());
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
J-M-L
August 9, 2021, 8:17pm
4
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.
system
Closed
December 7, 2021, 9:41pm
7
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.