[fpc-pascal]Bug with virtual methods
Peter Vreman
peter at freepascal.org
Tue Dec 31 13:16:43 CET 2002
> Hi!
>
>> That is correct behaviour of the compiler. The compiler only searches in
>> the scope of C2 for M1. It is the same as with 2 units. U1 and U2
>> instead
>> of C1 and C2.
>
> If the two methods have different names, the program compiles too. The
> compiler 'forgets' all overloaded methods except that one which is
> overridden.
>
> Why that? Shouldn all methods be treated as "seperate" ones? So, two
> methods with different names are "equally different" as two methods with
> just different parameters?
It is the scope in which the compiler searches for symbols. When there
would be no scope then you will end up with ambigious situations like:
type
c=class
procedure M1(s:string);
procedure p;
end;
procedure M1(i:integer);
begin
end;
procedure c.M1(s:string);
begin
end;
procedure c.p;
begin
m1(10);
end;
And with the overload directive to support cross unit and inherited
overloading we've found a good solution. And also very important is that
it is delphi compatible.
More information about the fpc-pascal
mailing list