I'm beginner to C++ and I'm doing one of the exercises about abstract class and inheritance.
This is my abstract class:
#ifndef SHAPE_H
#define SHAPE_H
class Shape
{
public:
virtual void area();
virtual void perimeter();
virtual void volume();
};
#endif
This is my concrete class that implements the abstract class:
#include <iostream>
#include <cmath>
#include "Shape.h"
using namespace std;
class Circle : public Shape
{
public:
Circle(int);
private:
int r;
};
Circle::Circle(int rad)
{
r = rad;
}
void Circle::area()
{
cout << "Area of this cirle = " << 3.14 * pow(r, 2) << endl;
}
void Circle::perimeter()
{
cout << "Perimeter of this cirle = " << 2 * 3.14 * r << endl;
}
void Circle::volume()
{
cout << "Volume is not defined for circle." << endl;
}
I got red lines under area()
, perimeter()
, and volume()
in my Circle
class, which showed "Error: inherited member is not allowed"
. I went through my class ppt and googled for answer but no luck. Any help is appreciated.