⭐ in reply to How do I make deterministic constructors?
I don't think you can do this in Perl, because Perl's version of prototypes isn't the same as C++'s. Differently-prototyped subroutines with the same name don't fly in Perl. I don't think.
My question would be: are you sure you need to do this? Perhaps there's a better way of handling this in Perl that doesn't require such a thing.
One way to do it would be to pass in the parameters as a hash, then just dump that hash into the hash-reference object that you create:
Now people can create a new R object any way they please:package R; sub new { my $this = shift; my $class = ref($this) || $this; my $self = { @_ }; bless $self, $class; }
and so on. Would that work for you?my $r1 = new R; my $r2 = new R (foo => 'bar'); my $r3 = new R (baz => 'quux', foo => 'bar');
|
|---|