Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot virtualize a function with optional argument #653

Open
HGuillemet opened this issue Feb 17, 2023 · 3 comments
Open

Cannot virtualize a function with optional argument #653

HGuillemet opened this issue Feb 17, 2023 · 3 comments

Comments

@HGuillemet
Copy link
Contributor

HGuillemet commented Feb 17, 2023

GIven this C++ function:

class M {
  public:
    virtual void f(bool b = true) {  }
};

The parser generates two methods:

    public native void f(@Cast("bool") boolean b/*=true*/);
    public native void f();

I want to virtualize f.
If I virtualize both methods:

    @Virtual public native void f(@Cast("bool") boolean b/*=true*/);
    @Virtual public native void f();

The generator produces a subclass with:

virtual void f() override;

that doesn't compile (error "marked override but doesn't override").
If I virtualize only one:

@Virtual public native void f(@Cast("bool") boolean on/*=true*/);
public native void f();

The generator produces a wrapper with:

          (dynamic_cast<JavaCPP_M*>(ptr) != NULL ? ((JavaCPP_M*)ptr)->f() : ptr->f());

that doesn't compile either (error "no matching function for call to 'JavaCPP_M::f()'").

Did I miss something or is there something to fix ?

@HGuillemet HGuillemet changed the title Cannot virtualizing a function with optional argument Cannot virtualize a function with optional argument Feb 17, 2023
@saudet
Copy link
Member

saudet commented Feb 18, 2023

We can't do that, we can't override the same method twice.

@saudet
Copy link
Member

saudet commented Feb 18, 2023

As for the default arguments, the virtual wrappers don't override with them, but I guess it's something that we could add.

@HGuillemet
Copy link
Contributor Author

HGuillemet commented Feb 18, 2023

I just realized that it's something the virtualize Info takes care of in addition of annotating with @Virtual : it prevents the creation of overloads for default arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants