Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-05

how to convert this to mode objfpc

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

misu kun

Hi
what is the equivalence of this code using mode objfpc ? btw , it compile fine with {$mode delphi}

type
     obj<T> = object
		x : T;
		class operator add (arg1 ,arg2 : obj<T>):obj<T>; inline;
     end;
class operator obj<T>.add (arg1 ,arg2 : obj<T>):obj<T>;
begin
	result.x := arg1.x + arg2.x;
end;

Reply by email

misu kun
to Graeme Geldenhuys

thanks
in objfpc mode i can imagine this ,but it didn't work unless i specialize (obj)

type
     generic obj<T> = object
		x : T;
     end;
operator + (arg1 ,arg2 : obj):obj; // error : here (obj) needs specialization
begin
	result.x := arg1.x + arg2.x;
end;

Reply by email

Sven Barth
to misu kun
"misu kun" wrote
thanks in objfpc mode i can imagine this ,but it didn't work unless i specialize

(obj)

Show quoted text 7 lines
type generic obj<T> = object x : T; end; operator + (arg1 ,arg2 : obj):obj; // error : here (obj) needs

specialization

begin result.x := arg1.x + arg2.x; end;

The method needs to be part of the object (you should use "record" though) like in the mode-Delphi-code, for this you need to add {$modeswitch advancedrecords} after the {$mode objfpc} directive.

Regards,
Sven

Reply by email

Sven Barth
to Sven Barth
"Sven Barth" wrote 5 lines
Am 11.05.2015 16:49 schrieb "misu kun" : > > thanks > in objfpc mode i can imagine this ,but it didn't work unless i

specialize (obj)

Show quoted text 7 lines
> > > type > generic obj<T> = object > x : T; > end; > operator + (arg1 ,arg2 : obj):obj; // error : here (obj) needs

specialization

Show quoted text 5 lines
> begin > result.x := arg1.x + arg2.x; > end; The method needs to be part of the object (you should use "record"

though) like in the mode-Delphi-code, for this you need to add {$modeswitch advancedrecords} after the {$mode objfpc} directive.

And just to be clear: it needs to be "class operator +" inside of "obj".

Regards,
Sven

Reply by email