AnsweredAssumed Answered

HLP: Problem with Virtual Function

Question asked by Venkatesh TK on Dec 8, 2008
Latest reply on May 26, 2011 by Ricardo Raupp
Hi,

I have a base class
-----------------------------------------------------------------------------------------------------
class cBaseClass
{
    public:
        // functions
       cBaseClass();
        ~cBaseClass(){};
       
        void testMainLoop(void);
        virtual void test_DummyFunction(void) = 0;
        void test_NoVirtual(void);
};
-----------------------------------------------------------------------------------------------------
I have derived this class from derived class.

class cDerivedClass : public cBaseClass
{
    public:
        // functions
        cDerivedClass();
        ~cDerivedClass( void );
       
       void testCaller(void);
       void test_DummyFunction(void);            //override
};

----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

And in the Base class

void cBaseClass:: testMainLoop(void)
{
    /*.....SOme Statements....*/
    test_DummyFunction();                // This should call the function definition of test_DummyFunction
                                                          // which is written in the Derived Class
}


THat is

void cDerivedClass:: testDummyFunction(void)
{
    int x;

     x = 2;
}
----------------------------------------------------------------------------------------------------


As we can see in the above code, I'm calling the function testDummyFunction.
The control should go to the testDummyFunction  definition which is in the derived class.
But this is not happening. The control goes to some assembly routines.

I thought some stack corruption...or something like that might have happened.
But...when I replace the function call testDummyFunction(), by testNoVirtual(),
which is not a virtual function, then the control smoothly went to the non-virtual function.

Please help me to sort out this issue.
Details:
IDE:                   Codewarrior for Coldfire
Version:             6.4 Build 6
Processor:        MCF5485
RTOS:               Threadx

Please let me know if you require further details.

Thanks,
Venkatesh





Outcomes