How to override function?

Zarathustra adam.chrapkowski at gmail.com
Thu Oct 22 12:02:23 PDT 2009


I would like to know, how to override function if subclass and super class are located in the same package and different modules.

For instance when they are in the same module:
//___________________________________
module main;
class Foo{

  this(){
    proc();
  }
  
  void proc(){
    writefln("Foo");
  }
}

class Bar : Foo{
  override void proc(){
    writefln("Bar");
  }
}

void main(){
  new Bar;
}
//___________________________________
the result is "Bar" so it's great, but:

//___________________________________
module pack.foo;

class Foo{

  this(){
    proc();
  }
  
  package void proc(){ // without 'package' it works well
    writefln("Foo");
  }
}

//___________________________________
module pack.bar;

class Bar : Foo{
  package override void proc(){ // without 'package' it works well
    writefln("Bar");
  }
}
//___________________________________
module main;
void main(){
  new Bar;
}
//___________________________________
the result is "Foo" so it's unexpected to me.


More information about the Digitalmars-d-learn mailing list