tags:

views:

1468

answers:

4

I'm having problem regarding max and sqrt

If I include math.h it coudn't find sqrt.

So I view the cmath header file and inside it includes math.h, but when I try to open math.h it says that file is not found. SO ithink my math.h is missing in Linux.

+3  A: 

Sorry I found the answer.

I just need to write it this way:

std::max std::sqrt

But Why does it work without "std::" under Windows OS?

It depends on your compiler. Some don't correctly place the functions in the C standard library into the std namespace.
Kristo
I think the windows.h header files define min and max as macros. They can be disabled by defining NOMINMAX before including said file.
jon hanson
+3  A: 

NB: in C++ you should #include <cmath> not #include <math.h>

NB: also specifying the namespace is a good practice

dfa
+1  A: 

Your system likely has the C headers in one place in the file system, and the C++ headers in another. Are you familiar with the actual list of directories searched for system headers? (Actually, the implementation is not required to have system header files, although all the ones I'm familiar with do. The C++ standard has requirements on what the statement #include <cmath> has to do, but not on how it has to be done.)

In your answer, you talk about variations between C++ on Linux and Windows. These are not OS-specific, but rather implementation-specific. You're probably using Visual C++ on Windows and something else on Linux (if only because VC++ runs only on Windows). They may work differently in default configurations.

In fact, #include <math.h> should be like #include <cmath>, except that math.h should move all its function names and such into the std:: namespace. If this isn't happening in your Linux C++ system, there's a problem. Unfortunately, you haven't provided nearly enough information to figure out what's happening.

David Thornley
+3  A: 

It's possible that the reason that you did not need to use std:: previously, is because somewhere in a headerfile the following statement was written:

using namespace std;

After this statement, the 'std::' prefix is not necessary anymore.

Hope this clarified things...

Arnaud Gouder