home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16373 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.2 KB  |  71 lines

  1. Path: sparky!uunet!ukma!wupost!cs.utexas.edu!usc!news.service.uci.edu!orion.oac.uci.edu!assist
  2. From: assist@orion.oac.uci.edu (ASSIST Coordination Site)
  3. Subject: New Employee Test
  4. Nntp-Posting-Host: orion.oac.uci.edu
  5. Message-ID: <assist.721943530@orion.oac.uci.edu>
  6. Newsgroups: comp.lang.c++
  7. Lines: 61
  8. Date: 16 Nov 92 20:06:10 GMT
  9.  
  10.  
  11. Hi everyone,
  12.  
  13. i am in the process of hiring 2 C++ programmers.  This Wednesday 11/18/92
  14. we are cunducting the final interviews with 4 candidates.
  15.  
  16.  
  17. I have a C++ question I would like them to address (sort of a programming test, but not really) but I'm not sure if it's too simple or too complex.
  18.  
  19. I could also use some suggestions on what might be usefull to ask them.
  20.  
  21. The question follows:
  22.  
  23. The following program makes use of a class (TestClass) with a static data member (count) that keeps track of the number of instances of the class that currently exist.  Suprisingly, however, the output of this program is "1 object(s) currently exist."  Why did this happen?  What changes can you make to correct the problem?
  24.  
  25. #include <iostream.h>
  26.  
  27. class TestClass {
  28.         int value;
  29.         static int count;
  30. public:
  31.         TestClass(int newValue=0) : value(newValue) {count++;}
  32.         ~TestClass() {count--;}
  33.         int getValue() {return value;}
  34.         friend int getTestClassCount();
  35. };
  36.  
  37. int getTestClassCount() {return TestClass::count;}
  38.  
  39. int TestClass::count = 0;
  40.  
  41. void main() {
  42.         TestClass a;
  43.         TestClass b=3;
  44.         {
  45.               TestClass c=a;
  46.         }
  47.         cout << getTestClassCount() << " object(s) currently exist" << endl;
  48. }
  49.  
  50.  
  51.  
  52. There it is .....  I would guess that many of the people on comp.lang.c++ know the answer.  Hint:  it has to do with the copy constructor.
  53.  
  54. I could really use some feedback on what you think about asking this type of question to determine whether someone really knows C++ or whether the've just read some books.
  55.  
  56. Any other suggestions for what to do during these interviews would be greatly appreciated.             
  57.  
  58. Thanks in advance for any responses before Wednesday.
  59.  
  60. Eric Taggart
  61. University of California
  62. eric@fs2.assist.uci.edu
  63.  
  64. P.S. Please feel free to either e-mail or post responses.  I will continue to monitor this area for a while.  Muchos Gracias. :)
  65.  
  66.     o
  67.  __/\_>
  68. (),> /()
  69.  
  70. --
  71.