qua*_*dev 5 c++ templates stl build visual-studio-2008
我想减少我正在处理的大型项目中.obj文件的大小(我知道链接器会删除重复的定义,但我想加快构建过程).其大小的原因之一是每个类使用std::vector<double>或std::vector<std::string>最终编译此类的代码并将其放在其.obj文件中.我试图显式实例化std::vector<double>和使用extern template声明,但它不起作用 - std::vector在Visual Studio C++中,STL具有内联的所有方法.如果没有修改STL代码(我不会这样做),有没有办法强制编译器不内联实例化方法并使用外部实例化版本std::vector<double>?
唯一想到的就是编写一个包含头来定义模板std::vector(但不是其成员,只需要声明这些成员)并包含它而不是vector标准头。
然后,您可以std::vector<whatever>在单独的编译单元中显式实例化并链接到该单元。
要显式实例化模板,请不要使用\xe2\x80\x99t extern template(这不会\xe2\x80\x99t工作),只需使用以下内容:
#include <vector> // The standard header, not your forward-declaration!\n\ntemplate class std::vector<double>;\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
375 次 |
| 最近记录: |