Path: utzoo!attcan!uunet!cs.utexas.edu!asuvax!ncar!mephisto!mcnc!decvax!shlump.nac.dec.com!ashok.dec.com!nadkarni From: nadkarni@ashok.dec.com Newsgroups: comp.lang.c++ Subject: Is this a bug ? Message-ID: <10259@shlump.nac.dec.com> Date: 13 Apr 90 12:37:07 GMT Sender: newsdaemon@shlump.nac.dec.com Organization: Digital Equipment Corporation Lines: 65 Am I doing something wrong or is this a bug in the compiler ? It appears as though the compiler tries to optimize by not copying the virtual table function pointer when assigning an object to another. Unfortunately, in this case it does not work. The compiler is Zortech C++ 2.06. I expected to see the output C A B and instead saw A A A Could someone please confirm this is a bug (in my code or the compiler). ---------------------- code follows ------------------ #include class C { public: virtual void output() {cout << "C\n";} }; class A : public C { public: virtual void output() {cout << "A\n";} }; class B : public C { public: virtual void output() {cout << "B\n";} }; union AB { class B b; class C c; class A a; }; main () { A a; B b; C c; AB ab; ab.c = c; ab.c.output(); ab.a = a; ab.a.output(); ab.b = b; ab.b.output(); } Thanks, /Ashok Nadkarni Digital Equipment Corp.