class House : public Structure { // Concrete(pun intended?) Class
public:
House();
~House();
int getCost();
int getBuildTime();
std::string getDescription();
};
House::House()
{}
House::~House()
{}
int House::getCost()
{
return 500;
}
int House::getBuildTime()
{
return 10;
}
std::string House::getDescription()
{
return"Lovely house to live in!";
}
1 2 3 4 5
class StructureFactory : public Structure {
public:
virtual Structure* createStructure() = 0;
};
int main()
{
StructureCreator<House> appCreator; // This line is the problem
// It compiles fine if my Structure class is not abstract
// Fails to compile if i make my structure class abstract
Structure *p = appCreator.createStructure();
return 0;
}
Using VS2010 with SP1 - VC++ Compiler spits out the following:
error C2259: 'StructureCreator<StructureType>'
: cannot instantiate abstract class
with
[
StructureType=House
]
due to following members:
int Structure::getCost(void) : is abstract
see declaration of 'Structure::getCost
int Structure::getBuildTime(void) : is abstract
see declaration of 'Structure::getBuildTime
std::string Structure::getDescription(void) : is abstract
see declaration of Structure::getDescription'