iostream为什么包含time.h? [英] Why does iostream include time.h?

查看:101
本文介绍了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*)’

  1. 为什么iostream包含time_t time(time_t*)?
  2. 为什么iostreamstd名称空间之外包含time_t time(time_t*)?
  3. (未答复)为什么删除template<class C>不会收到此错误?
  1. Why does iostream include time_t time(time_t*) ?
  2. Why does iostream include time_t time(time_t*) outside std namespace?
  3. (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屋!

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