this code, exact error @ bottom, i've looked throughout stack overflow , can't find answer question. have no idea why i'm getting error
//amer_bi.h #include <iostream> using namespace std; class amer_bi { public: int steps,i,j; double risk_free, price, strike, ttm, u, d, p, vol, disc, dt; char sw; double optionprice(double, double, double, double, double); double max(double , double); }; //amer_bi.cpp #include "amer_bi.h" #include <iostream> #include <math.h> #include <fstream> #include <string> #include <stdio.h> using namespace std; #include <string> //max function create double max( double d1, double d2 ) { return ( d1 > d2 ) ? d1 : d2; } double optionprice(double risk_free, double price, double strike, double ttm, double vol) { int steps; steps = 200; int i; int j; const int rows = steps+1; const int cols = steps+1; double dt = ttm/steps; double u = exp(vol*sqrt(dt)); double d = exp(-vol*sqrt(dt)); double p = .5 + ((risk_free - .5*vol*vol)/(2*vol))*sqrt(dt); double disc = exp(-risk_free*dt); //pointer code multidimensional dynamic array double **price_array; double **disc_array; double **call_array; price_array=new double*[rows]; disc_array=new double*[rows]; call_array=new double*[rows]; for(int i=0; i<rows; ++i) { price_array[i]=new double[cols]; disc_array[i]=new double[cols]; call_array[i]=new double[cols]; } /* //test data book example u = 1.1; d = .9091; disc = .9802; p = .5820; */ char sw = 'c'; disc_array[steps][steps] = price*pow(d,steps); (i=steps; > 0; i--) { disc_array[i-1][steps] = disc_array[i][steps]*u/d; } (i=steps; i>=0; i--) { (j=steps-1; j>=0; j--) { disc_array[i][j] = disc_array[i][j+1]*d; } } (i=steps; >= 0; i--) { if (sw == 'c') call_array[i][steps] = max(disc_array[i][steps] - strike, 0); else call_array[i][steps] = max(strike - disc_array[i][steps], 0); } price_array[0][steps] = price*pow(d,steps); (i=steps-1; >=0; i--) { (j=steps-1; j>=0; j--) { if (sw == 'c') call_array[i][j] = max(disc*(p*call_array[i][j+1] + (1-p)*call_array[i+1][j+1]), disc_array[i][j] - strike); else call_array[i][j] = max(disc*(p*call_array[i][j+1] + (1-p)*call_array[i+1][j+1]), strike - disc_array[i][j]); } } //std::cout << call_array[0][0] << endl; return call_array[0][0]; } //top.cpp #include <iostream> #include "amer_bi.h" using namespace std; int main () { amer_bi exa; exa.optionprice(.06, 100.0, 120.0, 1.0, .2); system("pause"); return 0; }
error lnk2019: unresolved external symbol "public: double __thiscall amer_bi::optionprice(double,double,double,double,double)" (?optionprice@amer_bi@@qaennnnnn@z) referenced in function _main 1>c:\users\class2017\documents\visual studio 2010\projects\qf 465\debug\amer_bi.exe : fatal error lnk1120:
the error getting because not implementing method amer_bi::option_price. implementing function option_price not method. result linker failing find methods implementation , raising lnk2019 error. implement method of class either need put implementation in class(marking method inline) or when implementing out side class refer name amer_bi::option_price knows method implement. e.g.
//.hpp file class foo{ public: //method prototype void method(); }; //.cpp file //what need doing void foo::method(){ //method implementation } //what doing void method(){ //function implementation }