Read-only archive of the All About Symbian forum (2001–2013) · About this archive

virtual tables related

0 replies · 1,312 views · Started 18 July 2006

Hello!

Could somebody tell me, why when I use casting from TAny * to some mixins and then call virtual function the result is not indexing in V table and calling the function? But if the class is not mixins and is derived from CBase everything is fine.

Here are two chunk of codes first is not working and second works. My question is releted to the first code.

// ---------------- first chunk of code ( NOT WORKED)

class MClass
{
[INDENT]public:
[INDENT]virtual void f()=0;[/INDENT][/INDENT]
};

class CClass : public CBase, public MClass
{
public:
[INDENT] static MClass * NewL()
{
[INDENT] return new (ELeave) CClass;[/INDENT]
}
[/INDENT]
private:
[INDENT] void f()
{
[INDENT] _LIT( KText2," virtual called \n"😉;
console->Printf( KText2); [/INDENT]
}[/INDENT]
};

// ...

TAny * obj = CClass::NewL();

static_cast< MClass *>( obj)->f();

// ---------------- second chunk of code ( WORKED)

class CMClass : public CBase
{
[INDENT]public:
[INDENT]virtual void f()=0; [/INDENT][/INDENT]
};

class CClass : public CMClass
{
public:
[INDENT] static CMClass * NewL()
{
[INDENT]CMClass * self = new (ELeave) CClass;
return self;[/INDENT]
}[/INDENT]

private:
[INDENT] void f()
{
[INDENT] _LIT( KText2," virtual called \n"😉;
console->Printf( KText2); [/INDENT]
}[/INDENT]
};

// ...

TAny * obj = CClass::NewL();

static_cast< CMClass *>( obj)->f();

// --- EOExs

Thanks in advance!