Alex Rivera | Logout

How to get C++ object name in run time?

Asked 2009-01-22T12:40:41.000
17

Can I get an object's name in run time (like getting an object's type via RTTI)? I want the object to be able to print its name.

Edit
Report

1 Answer

2

C++ objects don't have 'names' (unless I am understanding the problem wrong) Your best hope is to name them as you make them.

class NamedObject
{
  String name;
  NamedObject(String argname)
  { 
    name = argname;
  }
}

NamedObject phil("phil");
answered 2009-01-22T13:26:10.817

Your Answer