问题描述
有人声称使用命名空间std;
是不好的做法。其他人说它的确在它的地方。
Some people claim that using namespace std;
is bad practice. Others say it's OK in it's place. But everyone agrees that putting it in a header file is verboten.
亲爱的读者,可以从Bjarne Stroustrup自己的网站解释这一点。
So dear reader, who can explain this from Bjarne Stroustrup's own web site.
他甚至没有把它放在你可能注意到的顶部,大约50行。
He didn't even put it at the top where you might notice it, its about 50 lines down.
这里发生了什么事?
推荐答案
看到这是一个课程标题,我认为学生应该包括它,然后使用大部分的标准库。我很惊讶Stroustrup这样教(这是,在我看来,仍然是坏习惯),但它的确意味着他有一点点语法解释给他的学生。我不认为任何非课程应用程序(或更糟的是,图书馆)应该包括它,所以它可以说是有点可以接受。
Seeing as this is a course header, I think students are supposed to include it and then use most of the standard library that way. I am surprised Stroustrup teaches it that way (it is, in my opinion, still bad practice), but it does mean that he has one less bit of syntax to explain to his students. I don't think any non-coursework applications (or, even worse, libraries) are supposed to include it, so it's arguably somewhat acceptable.
我仍然认为它非常不好的风格,那说明标准的事情必须以 std ::
为前缀。
I still think it's very poor style, and that saying that standard things have to be prefixed with std::
would have been better.
这篇关于使用命名空间std;在头文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!