hi there
please see my header file and cpp file, when i compile them i get these error
classes.cpp:86.1: error: "vehicle::vehicle" names the constructor, not the type
classes.cpp:172.1: error: "driver::driver" names the constructor, not the type
here is my header file
#ifndef CLASSES_H_INCLUDED
#define CLASSES_H_INCLUDED
#include <iostream>
#include <string>
using namespace std;
class Vehicle;
class Driver {
private:
Vehicle * AssignedVehicle;
char * DriverName;
Driver * itself;
public :
Driver(string name, Vehicle * vehicle);
void setVehicle(Vehicle *vehicle);
bool removeVehicle();
string getName();
Vehicle * getVehicle();
};
class Vehicle {
private:
Driver * AssignedDriver;
char * VehicleName;
int VehicleCapacity;
public:
static const int VEHICLE_BIKE = 0;
static const int VEHICLE_CAR = 1;
static const int VEHICLE_BUS = 2;
static const int VEHICLE_LORRY = 3;
Vehicle(string name, Driver * driver, int capacity);
virtual string getTypeName();
virtual int getTypeCode();
void setDriver(Driver * driver);
void removeDriver();
Driver * getDriver();
int getCapacity();
string getName();
};
class Bus : public Vehicle {
private:
int vehicleType;
public:
Bus(string name, Driver * driver, int capacity);
virtual string getTypeName();
virtual int getTypeCode();
};
class Bike : public Vehicle {
private:
int vehicleType;
public:
Bike(string name, Driver * driver, int capacity);
virtual string getTypeName();
virtual int getTypeCode();
};
class Car : public Vehicle {
private:
int vehicleType;
public:
Car(string name, Driver * driver, int capacity);
virtual string getTypeName();
virtual int getTypeCode();
};
class Lorry : public Vehicle {
private:
int vehicleType;
public:
Lorry(string name, Driver * driver, int capacity);
virtual string getTypeName();
virtual int getTypeCode();
};
#endif // CLASSES_H_INCLUDED
here is my cpp file
#include "classes.h"
//============DRIVER CLASS====================
Driver::Driver(string name, Vehicle * vehicle)
{
//create space for name pointer
Driver::DriverName = new char[50];
//copy the name into the vehicleName variable
strcpy(Driver::DriverName, name.c_str());
//set the driver, might be null
Driver::AssignedVehicle = vehicle;
//address of this class
itself = this;
//if the vehicle is not null, set its driver to this driver
if (vehicle != NULL)
vehicle->setDriver(itself);
//display message
cout << "Message From Driver Class:\n\tNew driver has been created." << endl;
}
void Driver::setVehicle(Vehicle *vehicle)
{
//if the driver already having a vehicle
if (Driver::AssignedVehicle != NULL)
{
cout << "Selected driver has an assigned vehicle." << endl;
cout << "If you continue, the assigned vehicle will be replaced." << endl;
cout << "Do you want to continue? Please enter 'y' to continue." << endl;
cout << "Answer : ";
char answer;
cin >> answer;
//if answer is not equal 'y' and not equal 'Y'
if ( (answer != 'y') && (answer != 'Y') )
{
cout << "Cancelled." << endl;
return;
}
//remove this driver's vehicle's driver.. (itself)
this->AssignedVehicle->setDriver(NULL);
}
if (vehicle->getDriver() != NULL)
{
cout << "The selected vehicle has another driver assigned." << endl;
cout << "Please unassign the vehicle first." << endl;
}
else
{
//set this driver's vehicle to given vehicle
Driver::AssignedVehicle = vehicle;
//set given vehicles driver to this driver
cout << "THIS DRIVER : " << this->getName() << endl;
vehicle->setDriver(this);
}
}
bool Driver::removeVehicle()
{
//if the driver already having a vehicle
if (Driver::AssignedVehicle != NULL)
{
cout << "If you continue, the assigned vehicle will be unassigned." << endl;
cout << "Do you want to continue? Please enter 'y' to continue." << endl;
cout << "Answer : ";
char answer;
cin >> answer;
//if answer is not equal 'y' and not equal 'Y'
if ( (answer != 'y') && (answer != 'Y') )
{
cout << "Cancelled." << endl;
return false;
}
//remove vehicles driver
Driver::AssignedVehicle->setDriver(NULL);
//remove this drivers vehicle
Driver::AssignedVehicle = NULL;
}
else
{
cout << "The driver is not assigned to a vehicle." << endl;
}
return true;
}
Vehicle::Vehicle * Driver::getVehicle()
{
return Driver::AssignedVehicle;
}
string Driver::getName()
{
return Driver::DriverName;
}
//============END OF DRIVER CLASS===============
//============---VEHICLE CLASS---===============
Vehicle::Vehicle(string name, Driver * driver, int capacity)
{
//create space for name pointer
Vehicle::VehicleName = new char[50];
//copy the name into the vehicleName variable
strcpy(Vehicle::VehicleName, name.c_str());
//set the driver, might be null
Vehicle::AssignedDriver = driver;
//set the capacity
Vehicle::VehicleCapacity = capacity;
//display message
cout << "Message From Vehicle Class:\n\tNew vehicle has been created." << endl;
}
void Vehicle::setDriver(Driver * driver)
{
Vehicle::AssignedDriver = driver;
}
void Vehicle::removeDriver()
{
Vehicle::AssignedDriver = NULL;
}
Driver::Driver * Vehicle::getDriver()
{
return Vehicle::AssignedDriver;
}
int Vehicle::getCapacity()
{
return Vehicle::VehicleCapacity;
}
string Vehicle::getName()
{
return Vehicle::VehicleName;
}
string Vehicle::getTypeName()
{
return "Basic Vehicle";
}
int Vehicle::getTypeCode()
{
//vehicle does not have type
return -1;
}
//============END OF VEHICLE CLASS===============
//============---BUS CLASS---===============
Bus::Bus(string name, Driver * driver, int capacity)
: Vehicle::Vehicle(name, driver, capacity)
{
Bus::vehicleType = Vehicle::VEHICLE_BUS;
cout << "Message From Bus Class:\n\tNew bus has been added with capacity of " << capacity << endl;
}
string Bus::getTypeName()
{
return "Bus";
}
int Bus::getTypeCode()
{
return Bus::vehicleType;
}
//============END OF BUS CLASS===============
//============---BIKE CLASS---===============
Bike::Bike(string name, Driver * driver, int capacity)
: Vehicle::Vehicle(name, driver, capacity)
{
Bike::vehicleType = Vehicle::VEHICLE_BIKE;
cout << "Message From Bike Class:\n\tNew bike has been added with capacity of " << capacity << endl;
}
string Bike::getTypeName()
{
return "Bike";
}
int Bike::getTypeCode()
{
return Bike::vehicleType;
}
//============END OF BIKE CLASS===============
//============---CAR CLASS---===============
Car::Car(string name, Driver * driver, int capacity)
: Vehicle::Vehicle(name, driver, capacity)
{
Car::vehicleType = Vehicle::VEHICLE_CAR;
cout << "Message From Car Class:\n\tNew car has been added with capacity of " << capacity << endl;
}
string Car::getTypeName()
{
return "Car";
}
int Car::getTypeCode()
{
return Car::vehicleType;
}
//============END OF CAR CLASS===============
//============---LORRY CLASS---===============
Lorry::Lorry(string name, Driver * driver, int capacity)
: Vehicle::Vehicle(name, driver, capacity)
{
Lorry::vehicleType = Vehicle::VEHICLE_LORRY;
cout << "Message From Lorry Class:\n\tNew lorry has been added with capacity of " << capacity << endl;
}
string Lorry::getTypeName()
{
return "Lorry";
}
int Lorry::getTypeCode()
{
return Lorry::vehicleType;
}
//============END OF LORRY CLASS===============
so what is the mistake?