Recent

Author Topic: Error on overloaded function  (Read 1102 times)

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Error on overloaded function
« on: October 04, 2020, 07:54:27 am »
Hello,

I am using Lazarus 2.08 on a Windows 10, 64bit os.
I keep getting the following error on compilation:
“Error: Overloaded functions have same parameter list”, followed by this:
“Error: Found declaration: Gammp(real, real): double;

this is on a function:
Function PgmName.Gammp(a, x : real) : real;

This compiled and executed ok on Delphi XE, and I know that is not a valid reason why it should work here.  Is this because all of the declared variables in the program are typed as “double”, or is there another reason.

I would send the zipped file, but I do not know how to just zip one function from a project in Lazarus.

Here is the code for that function:
Function TFormMainErrorFunctionCalculator.Gammp(a, x : real) : real;
//
//  Returns the incomplete GAMMA Function P(a,x);
//
var
   //
   gamser, gammcf, gln : real;
   //
begin
   //
   If ( x < 0.0) or (a <= 0.0) then
      begin
        if MessageDlg('INVALID ARGUMENTS! Terminating Operation', mtConfirmation, [mbYes, mbNo], 0, mbYes) = mrYes then close;
      end;
   if x < a + 1.0 then
      begin
        gser(a, x, gamser, gln);
        gammp := gamser
      end
   else begin
        gcf(a, x, gammcf, gln);
        gammp := 1.0 - gammcf
   end
end;

It is called by several procedures in the project usually with call like this:
erf := gammp(0.5, sqr(x));
x is not a declared variable in my Var sections, but rather a result of other functions and is typed as “real”

Thank you for any insight you might be able to provide, I appreciate it very much.
John

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Re: Error on overloaded function
« Reply #1 on: October 04, 2020, 08:04:00 am »
UPDATE.
I changed all of my type declarations to "real" from "double" and the error is still there.  Does the sqr function return a double? or am I on the wrong track here?

John

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Error on overloaded function
« Reply #2 on: October 04, 2020, 09:51:36 am »
Project -> Publish project...
will produce a .zip of your project.
It is not usually possible to help with debugging based only on code snippets (which should at least be enclosed in tags so the page display  of this forum thread is decent).

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: Error on overloaded function
« Reply #3 on: October 04, 2020, 10:20:49 am »
I am able to generate the same error. Look at my code then you will know which line goes wrong:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Dialogs;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.   end;
  13.  
  14. var
  15.   Form1: TForm1;
  16.  
  17. implementation
  18.  
  19. {$R *.lfm}
  20.  
  21. procedure abc(const a: string);
  22. begin
  23.   ShowMessage('Hello ' + a);
  24. end;
  25.  
  26. procedure abc(const a: string);
  27. begin
  28.   ShowMessage(a);
  29. end;
  30.  
  31. end.

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Re: Error on overloaded function
« Reply #4 on: October 04, 2020, 10:42:19 am »
here is the zipped file (I think)

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: Error on overloaded function
« Reply #5 on: October 04, 2020, 10:50:31 am »
Exactly the same error as I showed you. In your case it is on the line #241 and line #425.

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Re: Error on overloaded function
« Reply #6 on: October 04, 2020, 11:27:08 am »
I am sorry I am so dense, I do not understand what the error is to which you are referring.  I apologize for my lack of understanding,
John

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: Error on overloaded function
« Reply #7 on: October 04, 2020, 11:38:45 am »
Lets see the image attached below.

The line #425 and #240 are the code copied/pasted from yours. What can you said about those 2 lines?

They are exactly the same.
Yes, that is the problem.

I don't know Delphi but in Free Pascal you are not allowed to have 2 functions with exactly same name and parameters.

Possible solutions:
- Remove one of them
- Pick one and change its name
- Use different parameters

CarmichaelJohn

  • New Member
  • *
  • Posts: 46
Re: Error on overloaded function
« Reply #8 on: October 04, 2020, 12:16:53 pm »
Handoko,
Thank you for your patience with me, I completely missed the duplication of that function.  That alleviated the error.  I very much appreciate your help.  However, now I have another problem, which I will start a new thread about.
Kind Regards, John

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: Error on overloaded function
« Reply #9 on: October 04, 2020, 01:19:15 pm »
This compiled and executed ok on Delphi XE, and I know that is not a valid reason why it should work here.  Is this because all of the declared variables in the program are typed as “double”, or is there another reason.

In FPC Real is an alias to the floating point type with the highest precision on the platform. For x86_64-win64 this is Double (for all other x86 platforms it's Extended and for essentially all other architectures it's Double as well), thus if you have two functions that return a Real and a Double each, then they'll essentially have the same result type, thus if they don't differ in their arguments (which they won't if one only has Double and the other has Real) then they'll have the same signature.

Solution: disable one of the two for platforms where Real = Double.

 

TinyPortal © 2005-2018