Just for the record, the Classes chapter were a *lot* of fun. Andrei kept the chapters relatively simple, so they're easy to grasp (imo). I thought I was going to spend weeks trying to understand classes in D, but the class features really tie in nicely together. I have yet to reach the operator overloading chapter ( it's pushed way back to chapter 12, I'm not sure why). I remember I had a really tough time understanding overloading in C++ many years ago, I'll see how this one goes..<br>
<br><div class="gmail_quote">On Sat, Aug 14, 2010 at 7:45 PM, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com">andrej.mitrovich@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
On page 217+218 there are two interfaces that define some final methods with the same name, and a class that inherits from both:<br><br>interface Timer<br>{<br> final void run() {}<br>}<br><br>interface Application<br>
{<br>
final void run() {}<br>}<br><br>class TimedApp : Timer, Application<br>{<br> void run() {} // cannot define run()<br>}<br><br>Okay, it hijacks both methods which are final, it won't compile which is what we want.<br>
TDPL states: "To access those methods for app of type TimedApp, you'd have to write app.Timer.run() and app.Application.run() for Timer's and Application's version", where the inheriting class does not hijack the methods.<br>
<br>So that would look like this:<br><br>interface Timer<br>{<br> final void run() {};<br>}<br><br>interface Application<br>{<br> final void run() {};<br>}<br><br>class TimedApp : Timer, Application<div class="im">
<br>{<br>}<br><br>
import std.stdio;<br><br>void main()<br>{<br></div> auto app = new TimedApp;<br> app.Timer.run(); // error, no Timer property<br> app.Application.run(); // error, no Application property<br>}<br><br>This looks to me like a DMD bug? I know I can do calls like these if a class inherits from another class:<br>
<br>class Timer<br>{<br> final void run() {};<br>}<br><br>class Application<br>{<br> final void run() {};<br>}<br><br>class TimedApp : Timer//, Application<div class="im"><br>{<br>}<br><br>import std.stdio;<br><br>
void main()<br>{<br></div>
auto app = new TimedApp;<br> app.Timer.run(); // works fine<br> //~ app.Application.run();<br>}<br><br>(Note I've had to comment out inheriting Application since MI is disallowed in D). This will now run. Is this a DMD bug?<div>
<div></div><div class="h5"><br>
<br><br><div class="gmail_quote">On Sat, Aug 14, 2010 at 4:56 PM, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I agree, NVI really looks like a nice idiom/pattern to me, I'd hate to loose it.<div><div></div><div><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>