I am trying to implement factory class and interface. But i am getting the below error message. I have created a factory class which decides which class to return NormalTaxManager or ImportedTaxManager. I have provided the abstraction using interface.
#include<iostream>
#include<vector>
using namespace std;
class TaxInterface
{
public:
virtual int calculate_tax(int price,int quantity)=0;
};
class TaxFactory
{
public:
// Factory Method
static TaxInterface *callManager(int imported)
{
if (imported == 0)
return new NormalTaxManager;
else
return new ImportedTaxManager;
}
};
class NormalTaxManager: public TaxInterface
{
public:
virtual int calculate_tax(int price,int quantity)
{
cout << "NormalTaxManager\n";
price=quantity*price*10/100;
return price;
}
};
class ImportedTaxManager: public TaxInterface
{
public:
virtual int calculate_tax(int price,int quantity)
{
cout << "ImportedTaxManager\n";
price=quantity*price*5/100;
return price;
}
};
int main()
{
TaxFactory f;
TaxInterface *a = f.callManager(1);
a->calculate_tax(100,2);
// int price=TaxInterface::callManager(1)->calculate_tax(100,2);
}
Problem:
error: ‘NormalTaxManager’ does not name a type
error: ‘ImportedTaxManager’ does not name a type