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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!concert!uvaarpa!murdoch!uvacs.cs.Virginia.EDU!rad2r
  3. From: rad2r@uvacs.cs.Virginia.EDU (Robert DeLine)
  4. Subject: Does anyone understand this quirk?
  5. Message-ID: <1992Nov17.073603.5235@murdoch.acc.Virginia.EDU>
  6. Sender: usenet@murdoch.acc.Virginia.EDU
  7. Organization: University of Virginia Computer Science Department
  8. Date: Tue, 17 Nov 1992 07:36:03 GMT
  9. Lines: 39
  10.  
  11.  
  12. For your amusement, please consider the following little program:
  13.  
  14.  
  15.      #include <iostream.h>
  16.      
  17.      class A
  18.      {
  19.        public:
  20.          A ()  { this->id(); }
  21.          virtual void id () const {  cout << "A\n"; } 
  22.      };
  23.      
  24.      
  25.      class B : public A
  26.      {
  27.        public:
  28.          B () : A() { }
  29.          virtual void id () const {  cout << "B\n"; }
  30.      };
  31.      
  32.      
  33.      main ()
  34.      {
  35.          B* bptr = new B();
  36.      }
  37.  
  38.  
  39.  
  40. The output I get from three different compilers is "A", but I was
  41. expecting to see "B".  Does a virtual function not become virtual till
  42. after the constructor is done?  What gives?  Is it my compilers or is
  43. this a bug in the language definition itself?  (Or is it just me? :)
  44.  
  45. Many thanks,
  46.  
  47. Rob DeLine
  48. Computer Science, University of Virginia
  49. deline@Virginia.EDU
  50.