使用cmath时禁用math.h废话 [英] Disable math.h crap when working with cmath

查看:240
本文介绍了使用cmath时禁用math.h废话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前遇到过一个问题,因为没有std::的函数就被重载了.而且诅咒仍然时有发生,因为我不使用using namespace std;.

I had a problem previously because of functions being overloaded without std::. And the curse is still happening every now and then because I don't use using namespace std;.

使用命名空间std进行删除会导致该程序得到废话的结果

是否有一种方法可以禁用所有来自c的非std函数,并且只能在名称空间std下使用c ++函数(而不必使用using namespace std;)?

Is there a way to disable all those non-std functions that come from c and only work with c++ functions under the namespace std (without having to use using namespace std;)?

换句话说:如果我使用sin()而不是std::sin(),我想得到一个错误,这样我就不会犯该错误.的c 不仅是罪过,而且还有与math.h冲突的每个功能.

In other words: I want to get an error if I use sin() rather than std::sin() so that I won't do that mistake. Of c ourse, not only for sin, but every function that has a conflict with math.h.

推荐答案

不幸的是,没有办法做到这一点.规则是#include <math.h>将所有名称放入全局命名空间,并且还允许将它们放入std::.同样,#include <cmath>将所有名称放入std::,并允许将它们也放入全局命名空间.允许使用多余的名称空间的原因仅仅是,如果不对现有的库进行大刀阔斧的操作,纯版本通常就无法实现,而这些库甚至可能不在C ++编译器的控制之下.

Unfortunately, there's no way to do that. The rule is that #include <math.h> puts all of the names into the global namespace, and is also allowed to put them into std::. Similarly, #include <cmath> puts all the names into std::, and is allowed to also put them into the global namespace. The reason for allowing the extraneous namespaces is simply that the pure versions are unimplementable in general without major surgery to existing libraries that may not even be under the control of the C++ compiler folks.

这篇关于使用cmath时禁用math.h废话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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