#include <iostream>
using namespace std;
class Vehicle
{
public:
Vehicle() {};
virtual ~Vehicle() {};
virtual void Move() = 0;
virtual void Haul() = 0;
};
class Car : public Vehicle
{
public:
Car() {};
virtual ~Car() {};
virtual void Move(int m) { cDist = m;
cout << "Vehicle moves " << cDist << " miles/hour
"; }
virtual void Haul() { cout << "Car s Hauling!
"; }
private:
int cDist;
};
class Bus : public Car
{
public:
Bus() {};
virtual ~Bus() {};
void Move(int m) { Move(m); }
void Haul() { "Bus is Hauling!
"; }
};
int main()
{
Vehicle* ptCar = new Car;
Vehicle* ptBus = new Bus;
ptCar->Move(1000);
system("pause");
return 0;
}
guys, why this code is giving me errors when trying to instantiate an object of Car, and Bus in main. I didn t intended to create an abstract class of Car and Bus, only of Vehicle... any help appreciated
1>------ Build started: Project: OperatorsTypes, Configuration: Debug Win32 ------
1> main.cpp
1>c:usersjorgedocumentsvisual studio 2010projectsshapesoperatorstypesoperatorstypesmain.cpp(36): error C2259: Car : cannot instantiate abstract class
1> due to following members:
1> void Vehicle::Move(void) : is abstract
1> c:usersjorgedocumentsvisual studio 2010projectsshapesoperatorstypesoperatorstypesmain.cpp(9) : see declaration of Vehicle::Move
1>c:usersjorgedocumentsvisual studio 2010projectsshapesoperatorstypesoperatorstypesmain.cpp(37): error C2259: Bus : cannot instantiate abstract class
1> due to following members:
1> void Vehicle::Move(void) : is abstract
1> c:usersjorgedocumentsvisual studio 2010projectsshapesoperatorstypesoperatorstypesmain.cpp(9) : see declaration of Vehicle::Move
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========