adding virtual function to the end of the class declaration avoids binary incompatibility?
Posted
by bob
on Stack Overflow
See other posts from Stack Overflow
or by bob
Published on 2010-05-18T18:02:13Z
Indexed on
2010/05/18
18:30 UTC
Read the original article
Hit count: 265
Could someone explain to me why adding a virtual function to the end of a class declaration avoids binary incompatibility?
If I have:
class A
{
public:
virtual ~A();
virtual void someFuncA() = 0;
virtual void someFuncB() = 0;
virtual void other1() = 0;
private:
int someVal;
};
And later modify this function to:
class A
{
public:
virtual ~A();
virtual void someFuncA();
virtual void someFuncB();
virtual void someFuncC();
virtual void other1() = 0;
private:
int someVal;
};
I get a coredump from another .so compiled against the previous declaration. But if I put someFuncC() at the end of the class declaration (after "int someVal"), I don't see coredump anymore. Could someone tell me why this is? And does this trick always work?
PS. compiler is gcc, does this work with other compilers?
© Stack Overflow or respective owner