T
Tony Johansson
Hello!
Assume you have an abstract class called Body and a derived class called
cylinder.
When you have an abstract class you can't instansiate an object.
As you can see in the abstract class there are one data member called
density that you can't access because there will not be any object of class
Body. The data member density will be inheritated and all the member
functions.
So when you have an instance of class Cylinder and you access setDensity you
will access the density that is inheritated from Body.
Now to my question: When you can't access any data member in an abstact
class is it then any point to declare any data member in such class. Why not
just declare them in the derived class instead?
class Body
{
public
virtual ~Body(){}
virtual const double getVolume() const = 0;
virtual const double getArea() const = 0;
double getDensity();
void setDensity(double);
private:
int density;
};
class Cylinder : public Body
{
public:
virtual const double getVolume();
virtual const double getArea();
private:
double radie, length;
};
//Tony
Assume you have an abstract class called Body and a derived class called
cylinder.
When you have an abstract class you can't instansiate an object.
As you can see in the abstract class there are one data member called
density that you can't access because there will not be any object of class
Body. The data member density will be inheritated and all the member
functions.
So when you have an instance of class Cylinder and you access setDensity you
will access the density that is inheritated from Body.
Now to my question: When you can't access any data member in an abstact
class is it then any point to declare any data member in such class. Why not
just declare them in the derived class instead?
class Body
{
public
virtual ~Body(){}
virtual const double getVolume() const = 0;
virtual const double getArea() const = 0;
double getDensity();
void setDensity(double);
private:
int density;
};
class Cylinder : public Body
{
public:
virtual const double getVolume();
virtual const double getArea();
private:
double radie, length;
};
//Tony