home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!concert!uvaarpa!murdoch!uvacs.cs.Virginia.EDU!rad2r
- From: rad2r@uvacs.cs.Virginia.EDU (Robert DeLine)
- Subject: Does anyone understand this quirk?
- Message-ID: <1992Nov17.073603.5235@murdoch.acc.Virginia.EDU>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Organization: University of Virginia Computer Science Department
- Date: Tue, 17 Nov 1992 07:36:03 GMT
- Lines: 39
-
-
- For your amusement, please consider the following little program:
-
-
- #include <iostream.h>
-
- class A
- {
- public:
- A () { this->id(); }
- virtual void id () const { cout << "A\n"; }
- };
-
-
- class B : public A
- {
- public:
- B () : A() { }
- virtual void id () const { cout << "B\n"; }
- };
-
-
- main ()
- {
- B* bptr = new B();
- }
-
-
-
- The output I get from three different compilers is "A", but I was
- expecting to see "B". Does a virtual function not become virtual till
- after the constructor is done? What gives? Is it my compilers or is
- this a bug in the language definition itself? (Or is it just me? :)
-
- Many thanks,
-
- Rob DeLine
- Computer Science, University of Virginia
- deline@Virginia.EDU
-