overriding private interface methods

Ali Çehreli acehreli at yahoo.com
Tue Oct 23 11:47:09 PDT 2012


On 10/23/2012 11:37 AM, Oleg wrote:
> Hello. How to override private methods?
>
> import std.stdio, std.conv;
>
> interface abcInterface
> {
> private double private_func();
> public final double func() { return private_func(); }
> }
>
> class abcImpl: abcInterface
> {
> override private double private_func() { return 3.14; } //#1
> }
>
> void main()
> {
> auto abc = new abcImpl;
> writeln( abc.func() );
> }
>
> This code generate error
> #1 Error: function inter.abcImpl.private_func cannot override a
> non-virtual function
>
> This private method (private_func) is 'private' because it must call
> only in final interface methods (func)

private member functions are not virtual by the design of the language. 
You have to make them 'protected', not private.

Ali


More information about the Digitalmars-d-learn mailing list