Hi am trying to write a program and its giving me this error "cannot instantiate abstract class", can someone help me please?
this is the code:
Header:
#ifndef ABSTRACTGEOMETRICOBJECT_H
#define ABSTRACTGEOMETRICOBJECT_H
#include <string>
using namespace std;
class GeometricObject
{
public:
GeometricObject();
GeometricObject(string color, bool filled);
public:
string getColor();
void setColor(string color);
bool isFilled();
void setFilled(bool filled);
string toString();
virtual double getArea() = 0;
virtual double getPerimeter() = 0;
private:
string color;
bool filled;
}; // Must place semicolon here
#endif
Cpp:
#include "GO.h"
GeometricObject::GeometricObject()
{
color = "white";
filled = false;
}
GeometricObject::GeometricObject(string color, bool filled)
{
this->color = color;
this->filled = filled;
}
string GeometricObject::getColor()
{
return color;
}
void GeometricObject::setColor(string color)
{
this->color = color;
}
bool GeometricObject::isFilled()
{
return filled;
}
void GeometricObject::setFilled(bool filled)
{
this->filled = filled;
}
string GeometricObject::toString()
{
return "Geometric object color " + color +
" filled " + ((filled) ? "true" : "false");
}
Main:
#include <iostream>
#include "GO.h"
using namespace std;
int main()
{
string colour;
bool filed;
cout<<"Enter color"<<endl;
cin>>colour;
cout<<"Enter is filled or not"<<endl;
cin>>filed;
GeometricObject g(colour, filed);
g.setColor(colour);
g.setFilled(filed);
cout<<"The color is "<<g.getColor()<<endl;
cout<<"The object is "<<g.isFilled()<<endl;
cout<<g.toString()<<endl;
system("pause");
return 0;
}
thnx