Path: utzoo!attcan!uunet!mitel!sce!cognos!kain From: kain@cognos.uucp (Kai Ng) Newsgroups: comp.lang.eiffel Subject: Re: redefinition and renaming Keywords: redefinition, renaming, dynamic binding Message-ID: <5529@corona.UUCP> Date: 10 Mar 89 21:48:25 GMT References: <2431@isis.UUCP> <5434@corona.UUCP> <694@m3.mfci.UUCP> <5506@corona.UUCP> Reply-To: kain@cognos.UUCP (Kai Ng) Organization: Cognos Inc., Ottawa, Canada Lines: 123 Sorry folks. The problem is my hands can type faster than my mind can think. The example provided in my previous article will not compiled if just entered as is. Thanks to Alan Myrvold (sp ?), my co-worker, who pointed that out to me. But I did code something correctly and got the result before I opened my mouth :-( In article <5506@corona.UUCP> kain@cognos.UUCP (Kai Ng) writes: > >CLASS B > >INHERIT > A REDEFINE classNumber > >FEATURE > > classNumber: Integer IS 2; > >END -- Class B >------------------------------------------------------------------------- >CLASS C > >INHERIT > A REDEFINE classNumber > > ... > classNumber: Integer IS 3 > ... >------------------------------------------------------------------------- You would get the following error message: "b", 6: Constant feature may not be redefined: classnumber *** es: error in pass2 Anyway the following is the correct example classes: -------------------------------------------------------------------------- CLASS A FEATURE classNumber: Integer IS DO Result := 1; END; -- classNumber print IS EXTERNAL printf LANGUAGE "C"; DO printf ("%d", classNumber); END; -- print END -- Class A -------------------------------------------------------------------------- CLASS B INHERIT A REDEFINE classNumber FEATURE classNumber: Integer IS DO Result := 2; END; -- classNumber END -- Class B -------------------------------------------------------------------------- CLASS C INHERIT A REDEFINE classNumber FEATURE classNumber: Integer IS DO Result := 3; END; -- classNumber END -- Class C -------------------------------------------------------------------------- CLASS D INHERIT B RENAME print AS printB, classNumber AS classB; C RENAME print AS printC, classNumber AS classC FEATURE Create IS EXTERNAL printf LANGUAGE "C"; DO printf ("\n printB prints "); printB; printf ("\n printC prints "); printC; END; -- Create END -- Class D -------------------------------------------------------------------------- Class D should be compiled as the rootClass and the following output should be expected: printB prints 3 printC prints 3 -------------------------------------------------------------------------- -- Kai Ng P.O. Box 9707 UUCP: uunet!mitel!sce!cognos!kain Cognos Incorporated 3755 Riverside Dr. (613) 738-1440 Ottawa, Ontario, ext. 6114 CANADA K1G 3Z4