iostream为什么包含time.h? [英] Why does iostream include time.h?
本文介绍了iostream为什么包含time.h?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下代码:
#include <iostream>
template<class C>
struct time { };
int main() { }
它产生(GCC 4.5):
It produces (GCC 4.5):
error: ‘template<class C> struct time’ redeclared as different kind of symbol
/usr/include/time.h:186:15: error: previous declaration of ‘time_t time(time_t*)’
- 为什么
iostream
包含time_t time(time_t*)
? - 为什么
iostream
在std
名称空间之外包含time_t time(time_t*)
? - (未答复)为什么删除
template<class C>
不会收到此错误?
- Why does
iostream
includetime_t time(time_t*)
? - Why does
iostream
includetime_t time(time_t*)
outsidestd
namespace? - (unanswered) Why, if I remove
template<class C>
, do I not get this error?
推荐答案
如果运行g++ -H -Wall -c testim.cc
(其中testim.cc
是示例),则会看到
If you run g++ -H -Wall -c testim.cc
(where testim.cc
is your example) you'll see that
.... /usr/include/c++/4.6/bits/ios_base.h
..... /usr/include/c++/4.6/ext/atomicity.h
...... /usr/include/c++/4.6/x86_64-linux-gnu/./bits/gthr.h
....... /usr/include/c++/4.6/x86_64-linux-gnu/./bits/gthr-default.h
........ /usr/include/pthread.h
......... /usr/include/sched.h
.......... /usr/lib/gcc/x86_64-linux-gnu/4.6/include/stddef.h
.......... /usr/include/time.h
因此,包含了<time.h>
以获得pthread支持.
So <time.h>
is included for pthread support.
这与Debian/Sid/AMD64上的GCC 4.6一起使用
This is with GCC 4.6 on Debian/Sid/AMD64
这篇关于iostream为什么包含time.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文