Struct polymorphism?

Ali Çehreli acehreli at yahoo.com
Mon Oct 8 15:39:01 PDT 2012


On 10/08/2012 03:19 PM, Era Scarecrow wrote:
 > On Monday, 8 October 2012 at 15:23:58 UTC, Era Scarecrow wrote:
 >> Error: function expected before (), not
 >> 'this.polyBase.opDispatch!("orig")'
 >
 > I think this is a compiler bug. It complains about calling opDispatch,
 > however it doesn't complain if you explicitly call 'this'. Should adding
 > 'this' be required?

I don't know all of the design decisions behind opDispatch, but I would 
be happier to have to type "this." when inside the struct. Otherwise, 
any struct that defined opDispatch would miss out on compiler's static 
name checking.

What if orig() has actually been a mistyped free-standing function name? 
Being forced to type this.orig() makes it explicit. And to me, this 
seems even better:

     return polyBase.orig(1);

 > I can't just
 > start adding 'this' to all my function as outside normal
 > functions/variables won't ever be seen.

Sorry, I can't understand the problem that you describe in that sentence.

Ali



More information about the Digitalmars-d-learn mailing list