std::map 和 -fno-implicit-templates

发布于 2024-09-13 08:01:41 字数 737 浏览 3 评论 0原文

我正在尝试使用 g++ 4.4 进行编译并链接一个使用 STL 的简单程序。 我正在尝试使用 -fno-implicit-templates 来完成此操作,因此所有模板都必须显式实例化。

我不明白为什么这段代码有效:

#include <map>
//template class std::map<char,char>;
template class std::_Rb_tree<char, std::pair <char const, char>,
               std::_Select1st<std::pair<char const, char> >, 
               std::less<char>, std::allocator<std::pair<char const, char> > >;

int main() {
   std::map <char,char> table;
return 0;
}

我希望该程序需要以下行:template class std::map;< /em>,但是该行不会使程序链接。需要 std::_Rb_tree 行。为什么?

预先感谢,任何提示将不胜感激。

I am trying to compile with g++ 4.4 and link a simple program that uses the STL.
I am trying to do it using the -fno-implicit-templates so all templates must be instantiated explicitly.

I don't understand why this code works:

#include <map>
//template class std::map<char,char>;
template class std::_Rb_tree<char, std::pair <char const, char>,
               std::_Select1st<std::pair<char const, char> >, 
               std::less<char>, std::allocator<std::pair<char const, char> > >;

int main() {
   std::map <char,char> table;
return 0;
}

I would expect that this program needs the line: template class std::map<char,char>;, however that line does not make the program link. The std::_Rb_tree line is needed. Why?

Thanks in advance, any hint will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琴流音 2024-09-20 08:01:41

地图在其实现中使用红黑树,因此您必须显式实例化地图实例化所需的树类型。恕我直言,这看起来不像是一个特别有用的编译器标志。

Maps use red-black trees in their implementation, so you have to explicitly instantiate the type of tree required for the instantiation of map. This does not look like a particularly useful compiler flag, IMHO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文