On Monday, 9 June 2014 at 16:13:50 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 15:54:21 UTC, Ivan Kazmenko wrote:
I'd expect a "multiple overrides of same function" error, much like if I just paste the mixin code by hand. Is that a bug or working by design? In the latter case, please explain the reasoning.

AFAIK, the rationale is that *should* a colision happen, the local symbol shadows the mixed-in symbol. Doing this avoid breaking your code just because someone added an extra member in their mixin, which happened to conflict with one of yours.

The idea is that you can workaround the issue by "naming" your mixin templates. Then, when you want to access members of the mixin template, you *know* it'll always work, regardless of what else may have been declared in your class.

That said, for something like virrtual functions, things get a bit trickier, since your *aren't* supposed to call them explicitly... I don't know if bug, or just surprising behavior.

Thank you for the explanation!

I've thought since that for classes, a template mixin of such kind can, and perhaps should, be replaced by inheritance from abstract classes or interfaces. There's likely no performance hit since the virtual table is already there anyway.

Still, I consider reporting this case as a maybe-bug to see more opinions. At least such shadowing is a case for a static code analysis tool.

Ivan Kazmenko.

Reply via email to