Instantiantion of abstract class  
Author Message
Yves1





PostPosted: Visual C++ General, Instantiantion of abstract class Top

I am not sure where I went wrong. I have extracted the additions in the *.cpp and *.h files.

: error C2259: 'PathDependentUpAndOutC' : cannot instantiate abstract class

In the cpp file:

"

//second one, Q2

PathDependentUpAndOutC::PathDependentUpAndOutC(const MJArray& LookAtTimes_,

double DeliveryTime_,

double Barrier_,

double Rebate_,

const PayOffBridge& ThePayOff_)

:

PathDependent(LookAtTimes_),

DeliveryTime(DeliveryTime_),

Barrier(Barrier_),

Rebate(Rebate_),

ThePayOff(ThePayOff_),

NumberOfTimes(LookAtTimes_.size())

{

}

unsigned long PathDependentUpAndOutC::MaxNumberOfCashFlows() const

{

return 1UL;

}

MJArray PathDependentUpAndOutC::PossibleCashFlowTimes() const

{

MJArray tmp(1UL);

tmp[0] = DeliveryTime;

return tmp;

}

unsigned long PathDependentUpAndOutC::CashFlows(const MJArray& SpotValues, double Barrier, double Rebate,

std::vector<CashFlow>& GeneratedFlows) const

{

int SpotSize = SpotValues.size();

for (int i=0; i<=SpotSize; ++i) {

double Spot = SpotValuesIdea;

if (Spot < Barrier) {

GeneratedFlows[0].TimeIndex = 0UL;

GeneratedFlows[0].Amount = ThePayOff(Spot);

}

else

{

GeneratedFlows[0].TimeIndex = 0UL;

GeneratedFlows[0].Amount = Rebate;

}

}

return 1UL;

}

PathDependent* PathDependentUpAndOutC::clone() const

{

return new PathDependentUpAndOutC(*this);

}

In the header file:

"

//

class PathDependentUpAndOutC : public PathDependent

{

public:

PathDependentUpAndOutC(const MJArray& LookAtTimes_,

double DeliveryTime_,

double Barrier_,

double Rebate_,

const PayOffBridge& ThePayOff_);

virtual unsigned long MaxNumberOfCashFlows() const;

virtual MJArray PossibleCashFlowTimes() const;

virtual unsigned long CashFlows(const MJArray& SpotValues, double Barrier, double Rebate,

std::vector<CashFlow>& GeneratedFlows) const;

virtual ~PathDependentUpAndOutC(){}

virtual PathDependent* clone() const;

private:

double DeliveryTime;

double Barrier;

double Rebate;

PayOffBridge ThePayOff;

unsigned long NumberOfTimes;

};

"



Visual C++6  
 
 
Aleksandr Tokarev





PostPosted: Visual C++ General, Instantiantion of abstract class Top

I think you haven't overriede some pure virtual method in PathDependent.

pure virtual method is a method that contains =0 in its declarartion.

class A

{

virtual void M() = NULL; // its pure virtual.

}


 
 
Yves1





PostPosted: Visual C++ General, Instantiantion of abstract class Top

I don't understand what you meant. Appreciate if you could put it in layman's terms because I am an absolute beginner having to run a race with professionals...

Below the whole *.cpp

//

//

//

// PathDependentAsian.cpp

//

//

#include <iostream>

#include <fstream>

#include <vector>

#include <iomanip>

#include <string>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <math.h>

#include <stdlib.h>

#include <cstdlib> // C++ standard library, for exiting data

#include <cctype>

#include <climits>

#include <list>

#include <functional>

#include <PathDependentAsian.h>

using namespace std;

PathDependentAsian::PathDependentAsian(const MJArray& LookAtTimes_,

double DeliveryTime_,

const PayOffBridge& ThePayOff_)

:

PathDependent(LookAtTimes_),

DeliveryTime(DeliveryTime_),

ThePayOff(ThePayOff_),

NumberOfTimes(LookAtTimes_.size())

{

}

unsigned long PathDependentAsian::MaxNumberOfCashFlows() const

{

return 1UL;

}

MJArray PathDependentAsian::PossibleCashFlowTimes() const

{

MJArray tmp(1UL);

tmp[0] = DeliveryTime;

return tmp;

}

unsigned long PathDependentAsian::CashFlows(const MJArray& SpotValues,

std::vector<CashFlow>& GeneratedFlows) const

{

double sum = SpotValues.sum();

double mean = sum/NumberOfTimes;

GeneratedFlows[0].TimeIndex = 0UL;

GeneratedFlows[0].Amount = ThePayOff(mean);

return 1UL;

}

PathDependent* PathDependentAsian::clone() const

{

return new PathDependentAsian(*this);

}

//my horrible start, Q1

PathDependentAsian_Geo::PathDependentAsian_Geo(const MJArray& LookAtTimes_,

double DeliveryTime_,

const PayOffBridge& ThePayOff_)

:

PathDependent(LookAtTimes_),

DeliveryTime(DeliveryTime_),

ThePayOff(ThePayOff_),

NumberOfTimes(LookAtTimes_.size())

{

}

unsigned long PathDependentAsian_Geo::MaxNumberOfCashFlows() const

{

return 1UL;

}

MJArray PathDependentAsian_Geo::PossibleCashFlowTimes() const

{

MJArray tmp(1UL);

tmp[0] = DeliveryTime;

return tmp;

}

unsigned long PathDependentAsian_Geo::CashFlows(const MJArray& SpotValues,

std::vector<CashFlow>& GeneratedFlows) const

{

double mult = SpotValues.mult();

double mean = pow(mult, 1/((double) NumberOfTimes));

// double mult = SpotValues.mult();

// double mean = pow(mult, 1/((double) NumberOfTimes));

GeneratedFlows[0].TimeIndex = 0UL;

GeneratedFlows[0].Amount = ThePayOff(mean);

return 1UL;

}

PathDependent* PathDependentAsian_Geo::clone() const

{

return new PathDependentAsian_Geo(*this);

}

//second one, Q2

PathDependentUpAndOutC::PathDependentUpAndOutC(const MJArray& LookAtTimes_,

double DeliveryTime_,

double Barrier_,

double Rebate_,

const PayOffBridge& ThePayOff_)

:

PathDependent(LookAtTimes_),

DeliveryTime(DeliveryTime_),

Barrier(Barrier_),

Rebate(Rebate_),

ThePayOff(ThePayOff_),

NumberOfTimes(LookAtTimes_.size())

{

}

unsigned long PathDependentUpAndOutC::MaxNumberOfCashFlows() const

{

return 1UL;

}

MJArray PathDependentUpAndOutC::PossibleCashFlowTimes() const

{

MJArray tmp(1UL);

tmp[0] = DeliveryTime;

return tmp;

}

unsigned long PathDependentUpAndOutC::CashFlows(const MJArray& SpotValues, double Barrier, double Rebate,

std::vector<CashFlow>& GeneratedFlows) const

{

int SpotSize = SpotValues.size();

for (int i=0; i<=SpotSize; ++i) {

double Spot = SpotValuesIdea;

if (Spot < Barrier) {

GeneratedFlows[0].TimeIndex = 0UL;

GeneratedFlows[0].Amount = ThePayOff(Spot);

}

else

{

GeneratedFlows[0].TimeIndex = 0UL;

GeneratedFlows[0].Amount = Rebate;

}

}

return 1UL;

}

PathDependent* PathDependentUpAndOutC::clone() const

{

return new PathDependentUpAndOutC(*this);

}


 
 
Aleksandr Tokarev





PostPosted: Visual C++ General, Instantiantion of abstract class Top

To unsewer your quations we need .h file where PathDependent class is declared.
 
 
Yves1





PostPosted: Visual C++ General, Instantiantion of abstract class Top

//

//

// PathDependentAsian.h

//

//

#ifndef PATH_DEPENDENT_ASIAN_H

#define PATH_DEPENDENT_ASIAN_H

#include <PathDependent.h>

#include <PayOffBridge.h>

class PathDependentAsian : public PathDependent

{

public:

PathDependentAsian(const MJArray& LookAtTimes_,

double DeliveryTime_,

const PayOffBridge& ThePayOff_);

virtual unsigned long MaxNumberOfCashFlows() const;

virtual MJArray PossibleCashFlowTimes() const;

virtual unsigned long CashFlows(const MJArray& SpotValues,

std::vector<CashFlow>& GeneratedFlows) const;

virtual ~PathDependentAsian(){}

virtual PathDependent* clone() const;

private:

double DeliveryTime;

PayOffBridge ThePayOff;

unsigned long NumberOfTimes;

};

class PathDependentAsian_Geo : public PathDependent

{

public:

PathDependentAsian_Geo(const MJArray& LookAtTimes_,

double DeliveryTime_,

const PayOffBridge& ThePayOff_);

virtual unsigned long MaxNumberOfCashFlows() const;

virtual MJArray PossibleCashFlowTimes() const;

virtual unsigned long CashFlows(const MJArray& SpotValues,

std::vector<CashFlow>& GeneratedFlows) const;

virtual ~PathDependentAsian_Geo(){}

virtual PathDependent* clone() const;

private:

double DeliveryTime;

PayOffBridge ThePayOff;

unsigned long NumberOfTimes;

};

class PathDependentUpAndOutC : public PathDependent_Barrier

{

public:

PathDependentUpAndOutC(const MJArray& LookAtTimes_,

double DeliveryTime_,

double Barrier_,

double Rebate_,

const PayOffBridge& ThePayOff_);

virtual unsigned long MaxNumberOfCashFlows() const;

virtual MJArray PossibleCashFlowTimes() const;

virtual unsigned long CashFlows_Barrier(const MJArray& SpotValues, double Barrier, double Rebate,

std::vector<CashFlow>& GeneratedFlows) const;

virtual ~PathDependentUpAndOutC(){}

virtual PathDependent_Barrier* clone() const;

private:

double DeliveryTime;

double Barrier;

double Rebate;

PayOffBridge ThePayOff;

unsigned long NumberOfTimes;

};

#endif

////////////

//

//

// PathDependent.h

//

//

//

#ifndef PATH_DEPENDENT_H

#define PATH_DEPENDENT_H

#include <Arrays.h>

#include <vector>

class CashFlow

{

public:

double Amount;

unsigned long TimeIndex;

CashFlow(unsigned long TimeIndex_=0UL, double Amount_=0.0)

: TimeIndex(TimeIndex_),

Amount(Amount_){};

};

class PathDependent

{

public:

PathDependent(const MJArray& LookAtTimes);

const MJArray& GetLookAtTimes() const;

virtual unsigned long MaxNumberOfCashFlows() const=0;

virtual MJArray PossibleCashFlowTimes() const=0;

virtual unsigned long CashFlows(const MJArray& SpotValues,

std::vector<CashFlow>& GeneratedFlows) const=0;

virtual PathDependent* clone() const=0;

virtual ~PathDependent(){}

private:

MJArray LookAtTimes;

};

//add

class PathDependent_Barrier

{

public:

PathDependent_Barrier(const MJArray& LookAtTimes);

const MJArray& GetLookAtTimes() const;

virtual unsigned long MaxNumberOfCashFlows() const=0;

virtual MJArray PossibleCashFlowTimes() const=0;

virtual unsigned long CashFlows(const MJArray& SpotValues, double Barrier, double Rebate,

std::vector<CashFlow>& GeneratedFlows) const=0;

virtual PathDependent_Barrier* clone() const=0;

virtual ~PathDependent_Barrier(){}

private:

MJArray LookAtTimes;

};

#endif


 
 
Damien Watkins - MSFT





PostPosted: Visual C++ General, Instantiantion of abstract class Top

Hello

Re: Instantiantion of abstract class

General C++ programming questions are outside the scope of this forum - for the scope of the VC General forum please look at: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=19445&SiteID=1

For such issues please consult a good text book or use a newsgroup (like the newsgroups at http://msdn.microsoft.com/newsgroups.)

OTP

Thanks

Damien