www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - abstract inheritance

reply Sean Kelly <sean f4.ca> writes:
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
Jul 24 2004
parent Nick <Nick_member pathlink.com> writes:
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
Jul 24 2004