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

inheritance & the necessity to define base method in derived class? #1204

Open
DannyDaiSun opened this issue May 28, 2021 · 0 comments
Open

Comments

@DannyDaiSun
Copy link

@ThePhD Hi, first of all thanks a lot for this great library, so useful. Second, regarding to your message of issue: #214

So this bothered me a lot. In the end, I actually ended up working hard on the implementation and enabling inheritance, as well as actual properties / variables. The usual caveats no longer apply: http://sol2.readthedocs.io/en/latest/api/simple_usertype.html

Give it a try with the latest (v2.14.0), and let me know if it's satisfactory.

does it mean, we no longer need to specify base class member methods when registering derived class via new_usertype? I have tried the following, which works as I expected, but I just worried if there would be a runtime overhead issue?

my code:

new_usertype<widget>(
    "widget",
    "draw", &widget::draw,
    "rotate", &widget::rotate
    );

new_usertype<button>(
    "button",
    "draw", &button::draw,
    sol::base_classes, sol::bases<widget>()
    );

context:
base class: widget
derived class: button
virtual function: draw
base class normal function: rotate

In summary, I wonder if my code is the best way of doing inheritance with sol?

Thank you in advance.

Originally posted by @DannyDaiSun in #214 (comment)

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

No branches or pull requests

1 participant