Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
Compiler
Delphi
Language
Overloading
Global
Method
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/Compiler/Delphi/Language/Overloading/Method
[ Add a report in this area ]
Report #:
45318
Status:
Closed
Sometimes compiler produces "Ambiguous call" error on overloaded methods, yet it shouldn't
Project:
Delphi
Build #:
10.0.2288.42451
Version:
10.0
Submitted By:
Vadim Yakovlev
Report Type:
Minor failure / Design problem
Date Reported:
5/1/2007 3:00:29 PM
Severity:
Infrequently encountered problem
Last Updated:
3/20/2012 2:24:39 AM
Platform:
All platforms
Internal Tracking #:
249971
Resolution:
Fixed
(Resolution Comments)
Resolved in Build:
:
12.0.3170.16989
Duplicate of:
None
Voting and Rating
Overall Rating:
(1 Total Rating)
5.00 out of 5
Total Votes:
None
Description
Consider this code. When I try to compile it, I get an error "Ambiguous call to A1" on a line C3.A1(AnsiString('')). It shouldn't be so. In all four classes, set of overloaded versions of A1 method are the same, with identical signatures, but somewhy only a call to String version of TClass3 produces this error, in other cases, compiler correctly selectes which method to call. If you comment out that line, then code compiles without any problems. Also, the last block of code, where TClass3 type instance is assigned to TClass1 type variable demonstrates that overriding works correctly, only selection of an overloaded method fails.
program Project1;
uses
Dialogs;
type
TClass1 = class
procedure A1(const S:String); overload; virtual;
procedure A1(const S:WideString); overload; virtual;
end;
TClass2 = class (TClass1)
procedure A1(const S:String); override;
end;
TClass3 = class (TClass1)
procedure A1(const S:WideString); override;
end;
TClass4 = class (TClass1)
procedure A1(const S:String); override;
procedure A1(const S:WideString); override;
end;
{ TClass1 }
procedure TClass1.A1(const S: String);
begin
ShowMessage('Ansi, 1');
end;
procedure TClass1.A1(const S: WideString);
begin
ShowMessage('Wide, 1');
end;
{ TClass2 }
procedure TClass2.A1(const S: String);
begin
ShowMessage('Ansi, 2');
end;
{ TClass3 }
procedure TClass3.A1(const S: WideString);
begin
ShowMessage('Wide, 3');
end;
{ TClass4 }
procedure TClass4.A1(const S: String);
begin
ShowMessage('Ansi, 4');
end;
procedure TClass4.A1(const S: WideString);
begin
ShowMessage('Wide, 4');
end;
var C1: TClass1; C2: TClass2; C3: TClass3; C4: TClass4;
begin
C1 := TClass1.Create;
try
C1.A1(AnsiString(''));
C1.A1(WideString(''));
finally
C1.Free;
end;
C2 := TClass2.Create;
try
C2.A1(AnsiString(''));
C2.A1(WideString(''));
finally
C2.Free;
end;
C3 := TClass3.Create;
try
C3.A1(AnsiString('')); //This line produces an error
C3.A1(WideString(''));
finally
C3.Free;
end;
C4 := TClass4.Create;
try
C4.A1(AnsiString(''));
C4.A1(WideString(''));
finally
C4.Free;
end;
C1 := TClass3.Create;
try
C1.A1(AnsiString(''));
C1.A1(WideString(''));
finally
C1.Free;
end;
end.
Steps to Reproduce:
1. Attempt to compile attached demo, you get an error.
2. Comment out or remove line "C3.A1(AnsiString(''));" and copile again - now there are no more problems.
Workarounds
None
Attachment
None
Comments
None
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us