Yes, you are right.

I realized that just after posting the question and deleted this post.
Somehow it never got deleted.

Thanks anyway.

-Nagappan


On Thursday, July 24, 2014 3:13:33 PM UTC+8, Bruce Mitchener wrote:
>
> It is a bug that it worked without optimization.
>
> When you call a virtual method from the constructor (indirectly in this 
> case), the class hasn't been fully constructed yet, so you can't call the 
> derived version of the method |foo|.
>
> This covers the topic pretty well:
>
>     
> http://www.parashift.com/c%2B%2B-faq-lite/calling-virtuals-from-ctors.html
>
> Does that help explain things?
>
>  - Bruce
>
>
>
> On Thu, Jul 24, 2014 at 1:55 PM, nagappan nachiappan <[email protected] 
> <javascript:>> wrote:
>
>> I have this file :
>>
>> #include <emscripten.h>
>> #include <stdio.h>
>>
>> class BaseClass
>> {
>> public:
>>     virtual void foo() = 0;
>>     
>>     BaseClass()
>>     {
>>         init();
>>     }
>>     
>>     void init()
>>     {
>>         foo();
>>     }
>> };
>>
>>
>> class DerivedClass : public BaseClass
>> {
>> public:
>>     DerivedClass() : BaseClass(){}
>>     
>>     virtual void foo()
>>     {
>>         printf("From DerivedClass");
>>     }
>> };
>>
>> int main()
>> {
>>     DerivedClass d;
>>     return 0;
>> }
>>
>> Without any compiler optimization , things work fine and I see the "From 
>> DerivedClass" message printed out.
>> But , I face an error when the compiler optimization flag is set to "-O2"
>>
>>       Uncaught Pure virtual function called!
>>
>> Any fix/work-around for this issue.
>>
>> -Nagappan
>>
>> -- 
>> 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