netbeans: 'max' was not declared in this scope

Sorry if my question is very rudimentary.

I have a simple class defined as:

 #ifndef PAYOFF1_H #define PAYOFF1_H class PayOff { public: enum OptionType {call,put}; PayOff(double Strike_,OptionType TheOptionType_); double operator()(double Spot) const; private: double Strike; OptionType TheOptionType; }; 

and the source file is:

#include "PayOff1.h" #include "minmax.h" PayOff::PayOff(double Strike_, OptionType TheOptionType_) : Strike(Strike_),TheOptionType(TheOptionType_) { } double PayOff::operator ()(double spot) const { switch(TheOptionType) { case call: return max((spot - Strike) , 0); case put: return max((Strike-spot) , 0); default: throw("unknown option found."); } } 

I get the error 'max' was not declared in this scope.

Thank you for your help in advance.

Regards,

2 Answers

I think you should specify the namespace you are using, like this:

std::max 

or

using namespace std; 

So, in the first case that part of code should look like this:

... case call: return std::max((spot - Strike) , 0); case put: return std::max((Strike-spot) , 0); ... 

In the second case:

#include "PayOff1.h" #include "minmax.h" using namespace std; ... 

Don't forget about namespace, it is important.

2

Problem solved! Replacing "minmax.h" with "algorithm" and using std::max. Thanks,

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like