How to overload member function pointer and a regualr member function

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 25 02:50:14 PDT 2017


On Monday, 24 April 2017 at 16:46:21 UTC, ParticlePeter wrote:
> I would like to have this kind of struct:
>
> struct Foo {
>   private int i;
>   void function( int i, float f ) bar;  // will be defined at 
> runtime
>   void bar( float f ) {
>     bar( i, f );
>   }
> }
>
> [...]
> How else can I get the required behavior?

Like this:

struct Foo1
{
     private void function(int,float) _bar;
     void bar(float){}
     void bar(int i, float f){_bar(i,f);}
}

Or like this:

struct Foo2
{
     private void function(int,float) _bar;
     void bar(float) {}
     void function(int,float) bar() {return _bar;}
}


First solution looks better:

(new Foo2).bar()(0,0f) // less good
(new Foo1).bar(0,0f) // better




More information about the Digitalmars-d-learn mailing list