My main program security1.cpp does not recognize my "Bond" class which is inherited from the "security class". I am not sure why (i think it has do to do with the header file) as the class is recognized in my securityPrice.cpp.Any help would be very appreciated.
here is "security1.cpp":
#include <iostream>
#include <string>
#include "securityPrice.h"
using namespace std;
int main()
{double price, discount, cashflow,value,tt;
int expiry;
string type1;
cout << "\nWhat type of security is it?\n";
getline(cin,type1);
cout << "\nWhat is the "<< type1 << "'s price?\n";
cin >> price;
cout << "\nWhat is your discount rate?\n";
cin >> discount;
cout << "\nWhat are the associated cashflows?\n";
cin >> cashflow;
cout << "\nIn how many periods will the "<< type1<< " be sold?\n";
cin >> expiry;
if (type1 == "bond")
{Bond s1;}
cout << "\nThe discounted price of your " <<type1<< " is:\n";
cout << value;
cin >> tt;
return 0;
}
It looks like class Bond is declared inside securityPrice.cpp. If that is the case, the
declaration of Bond has to be moved to a header file that security1.cpp can #include.
If I put the bond class wholesale in the securityprice.h and it still doesn't work. I would rather place the code in the securityprice.cpp and declare it in the header. What are the rules as far as inheritance and header files go? I dont mind making another header file for this subclass or putting it in the main but for elegance reasons would prefer not to.