【发布时间】:2019-08-06 13:38:32
【问题描述】:
以下代码给出了堆栈溢出:
function Func(x : Double) : Double; overload;
function Func(x : Integer) : Double; overload;
function Func(x : Double) : Double;
begin
Result := Func(Round(x));
end;
function Func(x : Integer) : Double;
begin
Result := 1.0;
end;
Integer 重载函数永远不会被调用,Double 重载函数会调用自身直到堆栈溢出。
以下代码按预期工作:
function Func2(x : Double) : Double; overload;
function Func2(x : Integer) : Double; overload;
function Func2(x : Double) : Double;
var
ix : Integer;
begin
ix := Round(x);
Result := Func(ix);
end;
function Func2(x : Integer) : Double;
begin
Result := 1.0;
end;
这是编译器错误还是预期行为?
【问题讨论】:
标签: delphi delphi-xe5 overload-resolution