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.
2Problem solved! Replacing "minmax.h" with "algorithm" and using std::max. Thanks,