Does changing the order of public non-virtual non-inline overloaded methods in a stand-alone class break the ABI?
Before:
class MyFinalClass
{
public:
// ...
void doSomething(char c, int i, int n);
void doSomething(char c, int i);
// ...
};
After:
class MyFinalClass
{
public:
// ...
void doSomething(char c, int i);
void doSomething(char c, int i, int n);
// ...
};
Thanks!
By default, methods are non-virtual, and they cannot be overridden. Virtual modifiers cannot be used with static, abstract, private, and override modifiers.
The non-virtual interface pattern (NVI) controls how methods in a base class are overridden. Such methods may be called by clients and overridable methods with core functionality. It is a pattern that is strongly related to the template method pattern.
The functions are linked by their name and signature, not by their position in the class. So no, you're not breaking the ABI.
Virtual functions are a different matter because they're linked by their position in a vtable (usually). This won't be a problem if you consistently recompile every file that depends on the header that defines the order, but if the class exists in a library it could be a concern.
There are two things that breaks the ABI when you update your classes. Virtual functions as pointed out by Mark (and remember that it is not because you did not mark a function as virtual that it isn't.)
The other things are inline functions because those make use of your variable members. If the order of your variable members changes then those inline's that were compiled in other software break too.
As pointed out by Russel Greene (see comment) the order of variable members can also cause alignment differences which is enough to change the size of the allocated objects. That also breaks your allocation (assuming the client's code uses new
)
And adding/removing members may not break the ABI (you still could allocate a byte here or a word there...) but that's usually a deal breaker right there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With