Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!ogicse!cvedc!gssc!gened From: gened@gssc.UUCP (Gene Daniel) Newsgroups: comp.lang.c++ Subject: Is this a Turbo C++ bug??? Message-ID: <6322@gssc.UUCP> Date: 6 Sep 90 07:07:07 GMT Distribution: usa Organization: Graphic Software Systems, Inc. Beaverton, Or. Lines: 67 I think that I have found a bug in Turbo C++. If this has been discussed here before feel free to ignore this article. The following program calls a member function in the base class which in turn calls a virtual member function. With Turbo the virtual function in the base class is called if the instance is a Base class or a Derived class. With Zortech the virtual function in the derived class is called if the instance is a Derived class and the function in the base class is called if the instance is a Base class, which is what I would expect. One interesting item is that if the base class is declared as virtual then things seem to work as they as they do in Zortech. Is this really a bug?? Which compiler got it right??? ---------------------------- Cut Here ------------------------------------ #ifdef __ZTC__ #include #else #include #endif class Base { int i; public: Base() {i = 0; } virtual void MemberFunc(char *instanceName) { cout << instanceName << ": virtual MemberFunc in Base\n"; } void CallMemberFunc(char *instanceName) { MemberFunc(instanceName); } }; class Derived: public Base { // change to virtual public Base and it works!!!! public: virtual void MemberFunc(char *instanceName) { cout << instanceName << ": virtual MemberFunc in Derived\n"; } }; main(int argc, char *argv[]) { Derived derived; Base base; base.CallMemberFunc("base"); derived.CallMemberFunc("derived"); } ---------------------------------- Cut Here ---------------------------------- The output from Zortech C++ is: base: virtual MemberFunc in Base derived: virtual MemberFunc in Derived The output from Turbo C++ is: base: virtual MemberFunc in Base derived: virtual MemberFunc in Base -- Gene Daniel | gened@gss.com Graphic Software Systems, Inc. | or P.O. Box 4900 | ..!tektronix!sequent!gssc!gened Beaverton, Oregon 97005-7161 |