Overloaded function disappears on polymorphism
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 24 11:01:10 PST 2015
On Sat, 24 Jan 2015 18:55:58 +0000, tcak wrote:
> main.d ===================================================
> class Car{
> public void makeBeep( char c ){}
> public void makeBeep( string s ){}
> }
>
> class Tesla: Car{
> override public void makeBeep( char c ){
> writeln("C = ", c);
> }
> }
>
> void main(){
> auto t = new Tesla();
>
> t.makeBeep("Model S");
> }
> ===================================================
>
> Error: function main.Tesla.makeBeep (char c) is not callable using
> argument types (string)
>
> For Tesla, I expected that makeBeep( string s ) would still be defined.
> Because I have overridden on makeBeep( char c ). Isn't that correct?
nope. overriding overloaded function cancels all overloads. it's by spec.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150124/cf6af9be/attachment.sig>
More information about the Digitalmars-d-learn
mailing list