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 );
  }
}

But apparently the function pointer and the member function cannot have the same name: Error: function main.Foo.bar conflicts with variable main.Foo.bar ...

I tried with an inner struct:
struct Foo {
  private int i;
void function( int i, float f ) bar; // will be defined at runtime
  private struct Inner {
    void bar( float f ) {
      bar( i, f );
    }
  }
  Inner inner;
}

But this time I get following error:
Error: need 'this' for 'i' of type 'int'

What does this message tell me? Should the inner struct not be able to access Foo.i?

How else can I get the required behavior?

I would prefer to avoid another indirection like this:
struct Foo {
  private int i;
void function( int i, float f ) bar; // will be defined at runtime
  void baz( float f ) {
    bar( i, f );
  }
  void baz( int ii, float f ) {
    bar( ii, f );
  }
}

Reply via email to