[fpc-devel]Proposal for audo-destructors
marc at dommelstein.net
Sun Sep 12 13:02:52 CEST 2004
At 08:42 12-9-2004, netsurfer at au.ru wrote:
>Absence of automatic construction/destruction of
>classes is very painfull and it can significantly
>development process (i.e. smart pointers and RAII are
>impossible). It's one of the greatest flaws of Pascal
>C (the second thing are Templates of cource). Are
>there any plans for serious language extensions in
>this way for "post
>2.0" releases of FPC ?
>P.S. The simpliest proposal for syntax for auto
>construction/destruction could be like (maybe with
> on constructors/destructors):
> Procedure Something;
> Var T:tMyClass;Auto;
> Begin <- T auto created here
> If ... Then Exit; <- T auto destructed here
> End; <- T auto destructed here
> P.P.S. The "auto" modifier should affect only stack
> There's no great need of this for global vars.
Again, what if you assign T to a global var or a class member ?
So in your example:
Begin <- T auto created here
GlobalT := T; <- What would this do ?
If ... Then Exit; <- T auto destructed here
End; <- T auto destructed here
IMO if you want such behaviour, you can use interfaces.
More information about the fpc-devel