问题
I have some code which is being built with GCC 5.3.1 without _GLIBCXX_CXX11_ABI set. Now, suppose I want to use both old-style and new-style std::__cxx11::string's in the same bit of code . Is that possible? If so, how?
Notes:
- I don't really have a good reason for doing this. I do have a not-so-good reason, but let's make it a theoretical question please.
- It's ok if the C++11 strings aren't called
std::string.
回答1:
Can you have both the old and new string implementation in the same code? Not exactly. The Almighty Manual states:
ABI transition adds new implementations of several components, using the
abi_tagattribute and the__cxx11inline namespace to distinguish the new entities from the old ones.
Use of the new or old ABI can be selected per-translation unit with the
_GLIBCXX_USE_CXX11_ABImacro.New non-reference-counted string implementation.
Now you could theoretically compile with -D_GLIBCXX_USE_CXX11_ABI=0 and use ext/vstring.h, which was GCC's conforming string implementation before the breaking ABI change. I wouldn't be surprised if things blew up, though.
来源:https://stackoverflow.com/questions/37623580/is-it-possible-to-use-c11-abi-and-both-cxx11-style-and-old-style-strings