c++ - Exporting template code = dangerous? (MSVC) -
As I have written in another question, I came across this issue when I came to 1.40 through MSVC 7 And raised many C24251 warnings.
Now, after reading the article, I wonder: Is it generally frustrating to export the template code, such as
class DLLEXPORT_MACRO AClass {public: Std :: vector & lt; Int & gt; GetVecCopy () {myVec; } ...}
This code has been compiled into a DLL through MSVC7.1. Although this code does not cause any errors referenced from another MSVC7.1 code, it is said that the MSVC8 code in this DLL correlates to runtime (memory alignment issues?). .
Because it is clearly bad ... What is a "best practice" to deal with the issue of exporting template code?
This is a bad idea, as the std :: vector is different or there is a difference between the compiler versions Could. However, this could possibly fail in load times, since the name of std :: vector should be different in compatible compiler versions (this name is part of the argument for mangling).
This link-time failure is something that can not actually be implemented as a developer, though in addition to purchasing a compiler supporting it. The second solution is to keep the template type completely out of the DLL interface. Keep them in private members.
Note that the problem is not unique to templates for a moment, imagine that std :: string
is UDT instead of typing, and the compiler is provided by runtime . It can still change between compiler versions and of course between compiler vendors. It will still be unusable in a DLL interface.
For these reasons, Practical Solutions 0. Use C, 1. Use COM or 2. Arrange on a compiler version.
Comments
Post a Comment