Brammie
Brammie

Reputation: 610

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 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?

Upvotes: 0

Views: 673

Answers (4)

Daniel
Daniel

Reputation: 31579

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

Upvotes: 2

IronMensan
IronMensan

Reputation: 6831

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.

Upvotes: 3

RushPL
RushPL

Reputation: 4805

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.

Upvotes: 0

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145419

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.,

Upvotes: 2

Related Questions