Thanks! By the destructor (sorry still learning) you mean ~Rect(); right? If I put a body i.e
{
}
I get an error saying expected a declartion.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
using namespace std;
class Shape
{
public:
virtual int getArea() = 0;
virtual int getEdge() = 0;
virtual void Draw() = 0;
};
class Rect : public Shape
{
private:
int height, width;
public:
Rect( int initWidth, int initHeight)
{
height = initHeight;
width = initWidth;
};
~Rect();
int getArea() { return height * width ; }
int getEdge() { return ( 2 * height ) + ( 2 * width ) ; }
void Drawn()
{
for ( int i = 0 ; i < height ; i++ ) {
for ( int j = 0 ; j < width ; j++ ) { cout << "x " ; }
cout << endl ; }
}
};
int main()
{
Shape* pQuad = new Rect( 3,7);// Error object of abstract class type "Rect" is not //allowed. Pure virtual function "Shape::Draw" has no overrider
Shape* pSquare = new Rect( 5,5);
pQuad -> Draw();
cout << "Area is " << pQuad -> getArea() << endl;
cout << "Perimter is " << pQuad -> getEdge() << endl;
pSquare -> Draw();
cout << "Area is " << pSquare -> getArea() << endl ;
cout << "Perimter is " << pSquare -> getEdge() << endl;
}
|
Errors are:
1> Source.cpp
1>c:\users\Admin\documents\visual studio 2012\projects\adt\adt\source.cpp(41): error C2259: 'Rect' : cannot instantiate abstract class
1> due to following members:
1> 'void Shape::Draw(void)' : is abstract
1> c:\users\Admin\documents\visual studio 2012\projects\adt\adt\source.cpp(9) : see declaration of 'Shape::Draw'
1>c:\users\Admin\documents\visual studio 2012\projects\adt\adt\source.cpp(42): error C2259: 'Rect' : cannot instantiate abstract class
1> due to following members:
1> 'void Shape::Draw(void)' : is abstract
1> c:\users\Admin\documents\visual studio 2012\projects\adt\adt\source.cpp(9) : see declaration of 'Shape::Draw'
I understand the error, but not how to fix it if that makes much sense?