how to get object name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aecsant
    New Member
    • Nov 2007
    • 1

    #1

    how to get object name

    hi ,

    i am trying to get the object name, see the code below, but not able to find method, what could be the code in place of ???????.

    #include "iostream"
    using namespace std;
    class A{
    public:
    int i;
    void printObjectname (){
    cout << ????????;//<--what could be here, to print the object name as 'objectA'
    }
    };

    int _tmain(int argc, _TCHAR* argv[])
    {
    A *objectA = new A();
    objectA->printObjectnam e();

    return 0;
    }
  • MarshMallow
    New Member
    • Nov 2007
    • 52

    #2
    If I got it right,you would like to print on screen a variable name.
    A complex and non-standard mechanism known as Reflection is able to explore Objects and Class features and now it is also available for C++ developers,than ks to CERN(http://seal.web.cern.c h/seal/documents/dictionary/reflex/doxygen/html/index.html);but I think that it's a too advanced subject for this kind of problem.
    I suggest you to add a new attribute(wich will store object_name) in the class and to pass this attribute to the constructor(con structor is missing in your code)
    I also suggest you to make class attributes all private

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      This is not going to work.

      You have a pointer to an object A and that pointer is named objectA.

      You cannot display the names of variables.

      Instead, learn to use your debugger.

      Comment

      Working...