:: std有时需要,有时不需要 [英] ::std sometimes needed, sometimes not

查看:77
本文介绍了:: std有时需要,有时不需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。为什么在一个文件中我不知道< cmath>我需要使用

std :: tan(...),在另一个文件中我包含< cassert>和std :: assert失败

来编译。在我的代码中我没有使用命名空间std;像我的头文件中的一些东西在std命名空间中有些东西,有些则不是。那是

是正确的,还是我的编译器(mingw,3.2我想)可怕的破坏? :o)


Thanx,

马丁


解决方案

2003年9月15日星期一20:41:01 -0400,Marcin Vorbrodt < MV ***** @ eos.ncsu.edu>写道:

你好。为什么在一个文件中我不知道< cmath>我需要使用
std :: tan(...),在另一个文件中我包含< cassert>并且std :: assert无法编译。


那是因为断言是一个宏。它并不存在于命名空间中;没有

宏。这是宏的一个问题;关于他们的好处

是他们可以选择行号等等。


我的代码中没有使用命名空间std;像我的头文件中的一些东西的接缝在std命名空间中,而有些则不是。这是
正确的


是的,但是只有少数几个标准宏。


或者是我的编译器( mingw,3.2我认为)可怕的破碎? :o)




Wrt。对于其他一些事情,是的,但它仍然是一个非常好的编译器。


好的,那么是否有一个C ++。做断言的方式?一个标准的C ++类/模板

或者断言的东西?另外,是否有一个C ++替代< cmath>?

Thanx,

Martin

" Alf P. Steinbach" ; <人*** @ start.no>在消息中写道

news:3f **************** @ News.CIS.DFN.DE ...

On星期一,2003年9月15日20:41:01 -0400,Marcin Vorbrodt
< mv ***** @ eos.ncsu.edu>写道:

你好。为什么在一个文件中我不知道< cmath>我需要使用
std :: tan(...),在另一个文件中我包含< cassert>和std :: assert
failsto compile。



那是因为assert是一个宏。它并不存在于命名空间中;没有
宏。这是宏的一个问题;关于他们的好处
是他们可以选择行号等等。

我的代码中没有使用命名空间std;像我的头文件中的一些东西的接缝在std命名空间中,而有些则不是。这是否正确



是的,但只有少数标准宏。

或是我的编译器(mingw,3.2我认为)可怕的破碎? :o)



Wrt。对于其他一些事情,是的,但它仍然是一个非常好的编译器。



Marcin Vorbrodt写道:

好的,那么有一个C ++做断言的方式?一个标准的C ++类/模板
或断言的东西?另外,是否有一个C ++替代< cmath>?




请不要在这里发帖。阅读常见问题解答第5部分发布

指南:

http://www.parashift.com/c++-faq-lite/

C ++没有任何断言 - 像内置(断言除外),但是你可以创建一些东西,可能使用异常类

来携带有关错误的信息。 Stroustrup在某个地方有一个例子,即b $ b。可能在The C ++ Programming Language中。


< cmath> *是* C ++的替代品。


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。


Hi there. How come when in one file i unclude <cmath> i need to use
std::tan(...), and in another file i include <cassert> and std::assert fails
to compile. Nowhere in my code i do using namespace std; Seams like some
things in my header files are in std namespace and some are not. Is that
correct, or is my compiler (mingw, 3.2 i think) horribly broken? :o)

Thanx,
Martin


解决方案

On Mon, 15 Sep 2003 20:41:01 -0400, "Marcin Vorbrodt" <mv*****@eos.ncsu.edu> wrote:

Hi there. How come when in one file i unclude <cmath> i need to use
std::tan(...), and in another file i include <cassert> and std::assert fails
to compile.
That''s because assert is a macro. It doesn''t live in a namespace; no
macro does. That''s one problem with macros; the nice thing about them
is that they can pick up things like line number and so on.

Nowhere in my code i do using namespace std; Seams like some
things in my header files are in std namespace and some are not. Is that
correct
Yes, but there are only a handful or so of standard macros.

or is my compiler (mingw, 3.2 i think) horribly broken? :o)



Wrt. to some other things, yes, but it''s still a very good compiler.


OK, so is there a "C++" way of doing assert? A standard C++ class/template
or something that does assert? Also, is there a C++ alternative to <cmath>?

Thanx,
Martin
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...

On Mon, 15 Sep 2003 20:41:01 -0400, "Marcin Vorbrodt" <mv*****@eos.ncsu.edu> wrote:

Hi there. How come when in one file i unclude <cmath> i need to use
std::tan(...), and in another file i include <cassert> and std::assert failsto compile.



That''s because assert is a macro. It doesn''t live in a namespace; no
macro does. That''s one problem with macros; the nice thing about them
is that they can pick up things like line number and so on.

Nowhere in my code i do using namespace std; Seams like some
things in my header files are in std namespace and some are not. Is that
correct



Yes, but there are only a handful or so of standard macros.

or is my compiler (mingw, 3.2 i think) horribly broken? :o)



Wrt. to some other things, yes, but it''s still a very good compiler.



Marcin Vorbrodt wrote:

OK, so is there a "C++" way of doing assert? A standard C++ class/template
or something that does assert? Also, is there a C++ alternative to <cmath>?



Please don''t top-post here. Read section 5 of the FAQ for posting
guidelines:

http://www.parashift.com/c++-faq-lite/

C++ doesn''t have anything assert-like built in (other than assert), but
you could certainly create something, probably using an exception class
to carry the information about the error. Stroustrup has an example of
this somewhere, IIRC. Probably in "The C++ Programming Language".

<cmath> *is* the C++ alternative.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


这篇关于:: std有时需要,有时不需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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