我在SimulationEngine基类中创建一个名为RiskFactor的枚举。
class SimulationEngine
{
public:
enum RiskFactor { interest_rate, equities, volatility };
SimulationEngine(double horizon, Wrapper<valuationFunction>& theFunction_, RiskFactor simulatedRiskFactor);
virtual void DoOnePath(double vol, double normvariate) = 0;
virtual SimulationEngine* clone() const = 0;
const virtual double GetHorizon();
const Wrapper<valuationFunction>& GetFunction() const;
RiskFactor simulatedRiskFactor;
protected:
double horizon;
Wrapper<valuationFunction> theFunction;
};
在派生类中,我有此方法,在调用对象“ TheFunction”的方法时使用RiskFactor枚举类型的“ simulatedRiskFactor”。
void OneStepBSEngine::DoOnePath(double vol, double normvariate)
{
double variance = vol * vol * horizon;
double rootVariance = sqrt(variance);
double itoCorrection = -0.5 * variance;
//double movedSpot = spotvalue * exp(drift * horizon + itoCorrection);
//spotvalue = movedSpot * exp(rootVariance * normvariate);
double factor = exp(drift * horizon + itoCorrection + rootVariance * normvariate);
theFunction->RiskFactorMultiply(factor, simulatedRiskFactor);
return;
}
我应该如何使类“ theFunction”查找它以识别枚举并允许我写最后一行(尚不可用:]
theFunction->RiskFactorMultiply(factor, simulatedRiskFactor);
该班级目前看起来像这样:
class valuationFunction
{
public:
valuationFunction(double TTM);
virtual void ValueInstrument() = 0;
virtual double GetValue() const;
virtual void RiskFactorAdd(double increment) = 0;
virtual void RiskFactorMultiply(double factor) = 0;
virtual void UpdateTTM(double timeStep);
virtual valuationFunction* clone() const = 0;
virtual ~valuationFunction() {}
private:
protected:
double f;
double TTM;
};
并且我希望能够使用枚举RiskFactor调用RiskFactorAdd和RiskFactorMultiply函数。
RiskFactorMultiply
的声明需要使用包含的类名来限定枚举名称。
class valuationFunction
{
// ...
virtual void RiskFactorMultiply(double factor, SimulationEngine::RiskFactor risk) = 0;
// ...
};