For example, there is a class:

class B { void print() { std::cout << имя объекта; return; }; } 

As in print() get the name of the object so that the result of the call:

 int main( void ) { B name; name.print(); return 0; } 

Was name

  • 2
    Add a name field to the object, save the object name in it at creation and then print. - VTT
  • @VTT wanted some other way to learn, without any practical value - Totem
  • 2
    Well, you can also write a QT moc preprocessor, and run it so that it adds these fields automatically at compile time. Or add reading debug symbols and extract from them information about the name of a variable in the source code (aka self-made reflection). - VTT
  • In general, most likely you do not need to do this, and if it seems that it is necessary, then I strongly advise you to think carefully about the program architecture. Something you have with her is not so likely - koresh
  • @koresh You are absolutely right, I don’t need to do that, but unhealthy curiosity doesn’t leave me - Totem

0