[fpc-pascal] "class" methods for objects

Helmut Hartl helmut.hartl at firmos.at
Fri Jul 16 10:23:51 CEST 2010


Hello,

while converting bullet physic code to native fpc, i would find it handy
to have something like "class" methods for objects. (Methods without 
self pointer)
  (It would enhance the readability of the code much, because I were not 
forced to
   move such c++ class functions to global functions)
Reading doc and wiki I found nothing similar.

A simple test of the below showed test code gives me the following 
impression.
a) It's not fully implemented
b) It's not handled right in the compiler
     (the code should not compile if the second writeln is commented)
c) It has to be used differently.

Thanks for comments,

helmut

----snip
program Project1;

type
   TestObject=object
     class function StaticFunction:boolean;
   end;

class function TestObject.StaticFunction: boolean;
begin
   result:=true;
end;

var o:TestObject;

begin
  writeln(o.StaticFunction);
  writeln(TestObject.StaticFunction); //(22,21) Error: Only static 
variables can be used in static methods or outside methods
end.
---snap




More information about the fpc-pascal mailing list