Thanks Brion. I tried it out and as you said, yup it works fine. This line 
in the documentation made me worried that this functionality wouldn't work:

Note

*Embind* must understand the fully-derived type for automatic downcasting 
to work.


But it looks like polymorphic invocation does'nt suffer from the 
downcasting problem.


Thanks!

-Arnab

On Tuesday, November 24, 2015 at 8:04:39 AM UTC-8, Brion Vibber wrote:
>
> Should work fine, as long as IFoo has a class binding and Foo derives from 
> it. Are you having any trouble with the implementation or defining the 
> bindings?
>
> -- brion
> On Nov 23, 2015 7:36 PM, "arnab choudhury" <[email protected] 
> <javascript:>> wrote:
>
>> Hey guys
>>
>> I have a question about whether we can use embind to invoke polymorphic 
>> functions on derived classes (when the derived class type definitions may 
>> not be known). For example, say I have a class Foo which derives from a 
>> pure virtual class IFoo. However, we don't publicly expose the class Foo, 
>> but rather expose a factory function that creates an IFoo pointer for you.
>>
>> // Exposed publicly
>> class IFoo
>> {
>> public:
>>     IFoo() = default();
>>     virtual ~IFoo()=default();
>>     virtual void Bar() = 0;
>> };
>>
>>
>> // Not exposed publicly 
>> class Foo
>> {
>> public:
>>    Foo() = default();
>>    virtual ~Foo() = default();
>>    virtual void Bar() override;
>> };
>>
>> // Exposed publicly 
>> std::shared_ptr<IFoo> MakeFoo()
>> {
>>     return std::shared_ptr<IFoo>(new Foo());
>> }
>>
>>
>> My question is; I want to create an emscripten binding so that non ASM JS 
>> code can invoke Bar on an IFoo pointer obtained via MakeFoo. Is that even 
>> possible with embind currently? The confusion I have is that embind needs 
>> to be told the code address of the function to be invoked. The only code 
>> address I could theoretically bind it to would be IFoo::Bar. But would we 
>> polymorphically transition to Foo::Bar (the way you would with normal C++) 
>> when invoking Bar on a JS object created with a call to Module.MakeFoo()?
>>
>>
>> Thanks in advance!
>> -Arnab
>>
>>
>> -- 
>> 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] <javascript:>.
>> 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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to