home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20047 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.3 KB  |  47 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ukma!gatech!darwin.sura.net!haven.umd.edu!news.umbc.edu!gmuvax2!twallace
  3. From: twallace@gmuvax2.gmu.edu (Todd Wallace)
  4. Subject: Re: name of object
  5. Message-ID: <1993Jan28.173602.5232@gmuvax2.gmu.edu>
  6. Organization: George Mason University, Fairfax, Va.
  7. References: <g++FAQ_01_15_1993_texi@ohm.berkeley.edu> <g++FAQ_01_15_1993_plain@ohm.berkeley.edu>
  8. Date: Thu, 28 Jan 1993 17:36:02 GMT
  9. Lines: 36
  10.  
  11. Here is an odd question for the OOP gurus:
  12. Is there a way for an object to know its own name?
  13.  
  14. For instance, let's say we declare the following class:
  15. class Lemon {
  16.     public:
  17.     //some stuff
  18. };
  19.  
  20. void main(void)
  21. {
  22.     Lemon A,B,C;
  23.  
  24.     A.tell_me_your_name;
  25.     B.tell_me_your_name;
  26.     C.tell_me_your_name;
  27. }
  28.  
  29. and I would like the output to be:
  30. A
  31. B
  32. C
  33.  
  34. Therefore, I have to declare a member function for Lemon that
  35. can look up its own name.
  36.  
  37. Can it be done? It would help a lot with debugging.
  38.  
  39.  
  40. ----------------------------------------------------------------
  41. |    Todd Wallace               |  "A pessimist is surprised   |
  42. |    twallace@gmuvax2.gmu.edu   |   as often as an optimist,   |
  43. |                               |   but always pleasantly."    |
  44. |                               |            - Robert Heinlein |
  45. ----------------------------------------------------------------
  46.  
  47.