RE: RFC 171 (v1) my Dog $spot should call a constructor implicitl y

[email protected] (Evan Howarth)
Newsgroups perl.perl6.language.objects
Message-ID <[email protected]>
> Why would the programmer become confused?  In C++ (a mainstream OO
> language), if a Dog constructor was defined that took a string as an
> argument, the string would be auto-converted to a Dog.

Yes, C++ implicitly treats single argument constructors 
as conversion constructors. They convert the data type 
of the argument into the expected class.

What if you don't want your constructor to act like a 
conversion operator? C++ requires you to use the 'explicit'
keyword.

I love the power of C++, but merely tolerate its syntax. 
I'd like to see Perl provide a better conversions syntax.

Perl might be able to deliver conversion operators without
constraining its constructor syntax. Perhaps we could steal
an idea from C#. C# expects you to define conversion
operators instead of implicitly using single-argument
constructors for that purpose. In Perl that might be:

1. Reserve 'CONVERT' for conversion constructors?

2. Add a ': conversion' declarator for functions used
   as conversion operators?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.