整个C ++ STL代码被包括在.h而不是.cpp / .c文件中的原因是什么? [英] What is the reason for the entire C++ STL code to be included in the .h rather than .cpp/.c files?

查看:84
本文介绍了整个C ++ STL代码被包括在.h而不是.cpp / .c文件中的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚下载了STL源代码,我注意到STL模板类的所有定义都包含在.h文件中。函数定义的实际源代码位于.h文件中,而不是.cpp / .c文件中。这是什么原因?

I just downloaded the STL source code and I noticed all the definition for the STL template classes are included in the .h file. The actual source code for the function definition is in the .h file rather than .cpp/.c file. What is the reason for this?

http://www.sgi.com/tech/stl/download.html

推荐答案

因为很少编译器实现模板的链接。这很难。

Because very few compilers implement linking of templates. It's hard.

这里有一个简短的但是(我认为)信息文章: http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=53

Here's a brief but (I think) informative article about it: http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=53

我说我想,因为它真的不是我非常熟悉的东西,除非它广泛未实现。我最初说的标准不需要它,但看看导出的定义在C ++ 03,我没有看到任何迹象,它是可选的。也许这只是一个失败的标准。

I say "I think" because it's really not something I'm very familiar with other than that it's widely unimplemented. I initially said the standard didn't require it, but looking at the definition of "export" in C++03, I don't see any indication that it's optional. Maybe it's just a failed standard.

这篇关于整个C ++ STL代码被包括在.h而不是.cpp / .c文件中的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆