Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Daivam

Trouble with max()

This topic is 5615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone else have any idea why this C++ code snippet doesn''t seem to want to compile? I keep getting this compiler error. C:\Programming\Learn\Learn1\Learn1.cpp(12) : error C2065: ''max'' : undeclared identifier
#include <algorithm>
#include <iostream>

using namespace std;


int main()
{
	double x = 5;
	double y = 10;

	double z = max(x, y);
	cout << z;

	return 0;
}

Thanks for your help.

Share this post


Link to post
Share on other sites
Advertisement
i dont think the macro max is defined, its what it says. Include windows.h or make a max macro.

#define max(a,b) (((a) > (b)) ? (a) : (b))

Share this post


Link to post
Share on other sites
Maybe I''ve never tried it before without the .h at the end, but doesnt it need to be:

#include <algorithm.h>
#include <iostream.h>

?

Phosphorous

Share this post


Link to post
Share on other sites
quote:
Original post by Daivam
Isn''t max() defined in the algorithm header file though?

MS define min and max macros, so they leave them out of algorithm. Consult the MSDN documentation for further details.

Share this post


Link to post
Share on other sites
quote:
Original post by Lektrix
quote:
Original post by phosphorous
Maybe I''ve never tried it before without the .h at the end, but doesnt it need to be:

#include <algorithm.h>
#include <iostream.h>

?

Phosphorous

No! It should definitely be algorithm and iostream, i.e. without the .h extension.



Oops! You are absolutely right. I didn''t look close enough to realize that he needed to use STL headers. Guess I shouldn''t post before my morning Mt.Dew

Share this post


Link to post
Share on other sites
you could always open up the header file and look through the macros and function prototypes to see what you have available.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!