V
vasanth kumar
I am writing a small example below. I want to know, is this allowed as per
the standard C++. We make an abstract class by making any membor method as
pure virtual. when we make it pure virtual, what is the meaning of providing
definition as shown below. are the code lines in bold are good practice.
class Vehicle {
public:
virtual void startEngine() = 0;
virtual ~Vehicle() {};
};
void Vehicle::startEngine()
{
}
class Car : public Vehicle {
public:
void startEngine(){
Vehicle::startEngine();
}
};
void main()
{
Car objCar=new Car();
objCar.Vehicle::startEngine();
}
Thanks,
Vasanth
the standard C++. We make an abstract class by making any membor method as
pure virtual. when we make it pure virtual, what is the meaning of providing
definition as shown below. are the code lines in bold are good practice.
class Vehicle {
public:
virtual void startEngine() = 0;
virtual ~Vehicle() {};
};
void Vehicle::startEngine()
{
}
class Car : public Vehicle {
public:
void startEngine(){
Vehicle::startEngine();
}
};
void main()
{
Car objCar=new Car();
objCar.Vehicle::startEngine();
}
Thanks,
Vasanth