[Tutor] method, type?
Alan Gauld
alan.gauld at btinternet.com
Wed Jan 6 19:24:34 EST 2016
On 06/01/16 18:57, Alan Gauld wrote:
>> The solution is to use constructors with different names, which C++
>> calls "named constructors".
>
> I stopped using C++ around v2 and it didn't have such a feature.
> Maybe its been added since. If so that's good to know. (Time
> for some googling methinks...)
>
OK, I Googled. It seems named constructors is just an
idiom not an actual language feature. Pity :-(
And the idiom consists of two things:
1) Providing public class (static) factory methods
2) Making the actual constructor(s) protected
This has a similar feel to named constructors and is
identical to how you would do it in Python (except
for the protected bit) or Java. It's not a true
constructor function it's just a factory (which calls
the true constructors).
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list