Code
Correct code for setPolicy() Method of carInsurance class
#include<iostream>
#include<string>
using namespace std;
class Insurancepolicy
{
public:
Insurancepolicy();
Insurancepolicy(int pNr, string pHolder, double aRate);
~Insurancepolicy();
void setPolicy(int pNr, string pHolder, double aRate);
int get_pNr();
string get_pHolder();
double get_aRate();
private:
int policyNr;
string policyHolder;
double annualRate;
};
class CarInsurance :public Insurancepolicy
{
public:
void setPolicy(int nPr, string pHolder, double aRate, double eValue);
private:
double excess;
};
void CarInsurance::setPolicy(int nPr, string pHolder, double aRate, double eValue)
{
Insurancepolicy::setPolicy(nPr, pHolder, aRate);
excess = eValue;
}
Reason setPolicy() is not legal definition in derived class
Now in InsurancePolicy class we have declared all the member variable as a private. So outside of this class we can no access this variable because its private access specifier.. .
CarInsurance class is derived from the InsurancePolicy class so CarInsurance class can no directly access the private member of the InsurancePolicy class. For this we have to use its public method to get and set member property.
Comments
Leave a comment