This form of generics is not available in FPC 3.0.4
I tried: Code: Pascal [Select][+][-]generic procedure printTArr<T>(sarr: T); var item: string; // BUT WHAT TO PUT HERE INSTEAD OF STRING? begin for item in sarr do write(item, ','); writeln; end;
Is there any way to have generic function here that will print any type of printable item array sent to it? Is it possible to have simple generic functions?
Yes, this works. But this means for generics, full class has to be defined and it cannot be done with just a generic function.
In the new version of FPC it is possible.
3.0.0. is several years old. So no wonder it does not work as expected.This feature works in 3.0.4 and higher.
unit1.pas(23,1) Fatal: Syntax error, "BEGIN" expected but "identifier GENERIC" found