[fpc-devel]Method overloading

Peter Vreman peter at freepascal.org
Tue Apr 29 13:12:01 CEST 2003


>> Hi!
>>
>> I've got another problem with the compiler. Stripped down the problem,
>> it comes out that the compiler doesn't work correctly with overloaded
>> methods.
>>
>> For example: Serial transmission of data, a base class:
>>   CSerialInterface
>> which implements some methods for sending.
>>   Send(Buf:Pointer;Length:LongInt); virtual; abstract;
>>   Send(St:String);                  virtual;
>>   Send(Buf:CCharBuffer);            virtual;
>> (CCharBuffer is a class which is a "smart" char buffer)
>>
>> Each serial interface type gets a descent class.
>> Type CRS232 = class(CSerialInterface) ... End;
>> Type CRS485 = class(CSerialInterface) ... End;
>> Type CRS422 = class(CSerialInterface) ... End;
>> (as examples). They only implement Send(Buf:Pointer;Length:LongInt);
>>
>> And CSerialInterface implements the other Send methods which are only
>> wrappers for the above one (look at "virtual" and "virtual abstract"
>> declarations in CSerialInterface):
>> Procedure CSerialInterface.Send(St:String);
>> Begin
>>   Send(@St[1],Length(St));
>> End;
>> (and analogous for the CCharBuffer method).
>>
>> CRS232 now has 3 Send methods:
>>   Send(Buf:Pointer;Length:LongInt);     { implemented there }
>>   Send(St:String);        { inherited from CSerialInterface }
>>   Send(Buf:CCharBuffer);  { inherited from CSerialInterface }
>
> Please try it with 1.1 compiler. Also for inherited overloading you need
> to specify the overload keyword explicitly.

I tried it myself under win32 and it works fine with 1.1:

C:\Down>pp11w -B bar
Hint: End of reading config file c:\pp\bin\fpc.cfg
Free Pascal Compiler version 1.1 [2003/04/29] for i386
Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Win32 for i386
Compiling bar.pas
Compiling serialinterface.pas
Compiling rs485.pas
rs485.pas(16,49) Hint: Conversion between ordinals and pointers are not
portable

Linking bar.exe
64 Lines compiled, 0.8 sec

C:\Down>pp11w bar
Hint: End of reading config file c:\pp\bin\fpc.cfg
Free Pascal Compiler version 1.1 [2003/04/29] for i386
Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Win32 for i386
Compiling bar.pas
Linking bar.exe
19 Lines compiled, 0.8 sec

C:\Down>bar
CSerialInterface.Send(St:String = "S.Send"):LongInt;
CRS485.Send(Buf:Pointer = 0006FE91;Length:LongInt = 6):LongInt;
sending: "S.Send"
Kein BUG!

C:\Down>





More information about the fpc-devel mailing list