This is just a theoretical question. I've run into a similar problem in the COM world and wondered if this is also applicable in the C++ world. I'm also aware that I could avoid this problem with the Pimpl Idiom.
Suppose I had a class A version 1. I shipped the header file and the library file to the clients.
Then one day, I updated A by adding some functions (which are not vi开发者_如何学JAVArtual and not overloading). Class A is now version 2.
Suppose version 2 was compiled in the same environment and settings as version 1.
My understanding is in the new library file, class A's size and vtable will not be changed. Also since no overloading functions are added, the clients will not call the wrong function. As a result, users are not required to recompile their code.
Are there any pitfalls for this assumption?
There are no pitfalls that I'm aware. The concept you're describing is called binary compatibility.
Because version 2 of class A is still binary compatible (as far as I'm aware) with version 1 of class A, then no recompile is required. The KDE Techbase article has a decent set of guidelines (with examples) to follow for maintaining binary compatibility.
http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++
精彩评论