Jump to content
pyscripter

Smart Pointers - Generics vrs non-generic implementastion

Recommended Posts

On 1/3/2019 at 2:11 PM, Микола Петрівський said:

@Rudy Velthuis Nice idea, but does not work well with automatic type inference:


var Bob := SmartPtr<TTalking>(TTalking.Create('Bob'));

 

The compiler needs a type for Bob so it can know it should return a TTalking (through the Implicit operator) and not a TSmartPtr<TTalking>. There is no way around that.

 

But you can do without the inference:  

var Bob: TTalking := SmartPtr<TTalking>(TTalking.Create('Bob'));

 

Edited by Rudy Velthuis

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×