Author Topic: Question about assignment operator overloading example in the Reference guide  (Read 1160 times)


  • Hero Member
  • *****
  • Posts: 1352

Starting on page 212 about overloading the assignment operator the Reference Guide gives an example starting with the definition of a complex data type as:

Code: Pascal  [Select]
  1. type
  2.   complex = record
  3.     re : real;
  4.     im : real;
  5.   end;
then states "This system can be used to declare a new type, and define an assignment for that type. For instance, to be able to assign a newly defined type ’Complex’ "

Code: Pascal  [Select]
  1. Var
  2.   C, Z : Complex; // New type complex
  4. begin
  5.   Z := C;         // assignments between complex types.
  6. end;

followed by: "The following assignment operator would have to be defined:"
Code: Pascal  [Select]
  1. Operator := (C : Complex) z : complex;
but that makes the compiler unhappy, outputting the error message:

"Error: impossible to overload assignment for equal types"

which makes sense since the overload in that case is unnecessary.

Is the example faulty or am I missing its point ?

I also checked the ucomplex unit to see if an assignment operator was defined for a (complex, complex) tuple and there wasn't one. That example is at least confusing.

Thank you for your help.

using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.


  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
I can confirm with trunk. What is your FPC version?

The guide should be for 3.0.4, page is here:

Maybe it is outdated part of guide. AFAIK only this overload is necessary now:
Code: Pascal  [Select]
  1. operator := (r : real) z : complex;
  2.      begin
  5.     end;
Lazarus 2.1.0 r61214:62238 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls:


  • Hero Member
  • *****
  • Posts: 1352
Hi Blaazen,

the Free Pascal Reference Guide I'm reading is stated to be for version 3.0.2.  Document version 3.0.2 as well, dated February 2017.

my environment is as follows:

Free Pascal v3.0.4
Lazarus v.1.8.2
Windows 7 64bit.

In the page you linked to, the compiler will complain about the statement:

Code: Pascal  [Select]
  1. Operator := (C : Complex) z : complex;

located on the 11th line (not counting blank lines.) It makes sense for the compiler to complain since for the same type, there is no need for an assignment overload which could actually cause problems.

It looks like the web page has the same problem as the Reference Guide pdf I am reading.

Thank you for looking into it.

using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.