开发者

Can't put math.h in a namespace

I'm doing some cross platform development, and I ran across another weird problem..

namespace Math 
{
    #include <math.h>
}

This is what I am trying to do. It works fine on iOS, but on Android everything inside math.h is not a member of Math when I try to compile it. After some 开发者_JAVA百科trial an error I found out that the ndk doesn't put the stuff in math.h in the namespace Math, as the functions do exist without the Math:: prefix. The big problem is that some functions in math.h clash with my own convenience functions. How can I fix this?


You really shouldn't try to put any system headers into a different namespace. The solution, as painful as it may be at this point in development, is to put all of your code into its own namespace.


What about <cmath>? it puts everything in std:: (in C++11).


Don't put your convenience functions in the global namespace.

Don't try to wrap math.h in a namespace.

There, all’OK now.

Cheers & hth.,


Probably something else includes math.h earlier in the preprocessor "pipeline". C includes check whether the sane include has been included earlier. In this case, the check #ifndef MATH_H resulted in excluding the whole file. Try placing your include with the namespace at the beginning of your .c files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜