Yes, that seems to work... thanks!!!!

-Josh

On 12/10/2015 11:19 PM, Brion Vibber wrote:
The template parameters for 'function' only seem to accept method pointers for the given type, not for a parent type, so this kinda borks up even though it feels like it *ought* to work to just pass in &Base::doSomething here.

(It might be worth filing as an issue on github so it doesn't get forgotten; seems like something that would come up at API boundaries.)


Try using a static_cast on the method pointer, from the base to the derived type:

EMSCRIPTEN_BINDINGS(bindo) {
    emscripten::class_<Derived>("Derived")
        .constructor()
.function("doSomething", static_cast<void(Derived::*)()>(&Base::doSomething));
}

It's a little verbose, but seems to do the right thing and doesn't require writing extra functions.

-- brion


On Thu, Dec 10, 2015 at 1:31 AM, Joshua Auerbach <[email protected] <mailto:[email protected]>> wrote:

    Let's say I have the following in C++

    |class Base {||
    ||public:||
    ||    void doSomething() { ||
    ||||//do something here ||
    ||||}||
    ||};||
    ||
    ||class Derived : public Base {||
    ||};|

    And I want to expose Derived to js including the inherited method
    doSomething (a toy example illustrative of a bigger issue)

    Is this possible without also exposing Base?  Or do I really need
    to recreate the entire class hierarchy in my bindings?

    I know these bindings work:
    |
    ||emscripten::class_<Base>("Base")||
    ||    .function("doSomething", &Base::doSomething);||
    ||
    ||emscripten::class_<Derived, emscripten::base<Base>>("Derived")||
    ||    .constructor();|

    But this does not:

    |emscripten::class_<Derived>("Derived")||
    ||    .constructor()||
    ||    .function("doSomething", &Derived::doSomething)|

    unless I change the C++ definition of Derived to

    |class Derived : public Base {||
    ||public:||
    ||    void doSomething() { Base::doSomething(); }||
    ||};||
    |
I never want Base to be exposed to js just the inherited method. Is there any way to expose those without recreating the hierarchy
    or making trivial overrides like I do above?

    Thanks!!!
    Josh

-- Dr. Joshua E. Auerbach
    Postdoctoral Researcher
    Laboratory of Intelligent Systems
    École Polytechnique Fédérale de Lausanne

-- You received this message because you are subscribed to the Google
    Groups "emscripten-discuss" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to [email protected]
    <mailto:[email protected]>.
    For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.


--
Dr. Joshua E. Auerbach
Postdoctoral Researcher
Laboratory of Intelligent Systems
École Polytechnique Fédérale de Lausanne

--
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to