July 24, 2004 abstract inheritance | ||||
---|---|---|---|---|
| ||||
I think it's a tad odd that this compiles: # class Writer # { # abstract void put (bit x){ printf( "bit\n" ); } # abstract void put (int x){ printf( "int\n" ); } # } # # class MyWriter : Writer # { # override void put (bit x){} # } I had assumed that thhis was the equivalent of the C++ code: # class Writer # { # virtual void put (bit x) = 0 { printf( "bit\n" ); } # abstract void put (int x) = 0 { printf( "int\n" ); } # } # # class MyWriter : Writer # { # virutal void put (bit x){} # } ie. that it forced the user to implement the functions and the bodies were provided as defaults. Sean |
July 25, 2004 Re: abstract inheritance | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | In article <cducnr$1731$1@digitaldaemon.com>, Sean Kelly says... > >I think it's a tad odd that this compiles: > ># class Writer ># { ># abstract void put (bit x){ printf( "bit\n" ); } ># abstract void put (int x){ printf( "int\n" ); } ># } ># ># class MyWriter : Writer ># { ># override void put (bit x){} ># } >[snip] Well, considering that the following just compiled and ran: # import std.stdio; # # class Writer # { # abstract void put(int x) {writefln("int: ", x);} # } # # void main() # { # Writer w = new Writer; # w.put(7); # } I'd say it looks like the 'abstract' attribute is completely ignored when you specify a function body. The docs are painfully low on details about the 'abstract' attribute, so I'm not really sure if this classifies as a bug :) Nick |
Copyright © 1999-2021 by the D Language Foundation