First of all, this is what I have:
main.cpp
#include <iostream>
using namespace std;
int main()
{
return 0;
}
vehicle.h
#ifndef VEHICLE_H_INCLUDED
#define VEHICLE_H_INCLUDED
#include <string>
#include <vector>
class Vehicle
{
public:
std::string id;
std::string model;
virtual ~Vehicle();
virtual void printVehicle()=0;
static bool checkID(std::string id);
private:
int yearOfConstruction;
protected:
Vehicle(std::string sid, std::string smodel, int syear);
};
#endif // VEHICLE_H_INCLUDED
vehicle.cpp
#include "vehicle.h"
//Vehicle Constructor
Vehicle::Vehicle(std::string sid, std::string smodel, int syear)
{
id = sid;
model = smodel;
yearOfConstruction = syear;
};
//checkID
bool Vehicle::checkID(std::string id)
{
std::vector<int> digits;
for (char c : id)
{
if(std::isdigit(c))
{
digits.push_back(c - '0');
}
else
{
digits.push_back(int(c));
}
}
if(digits.size() != 7) return false;
else
{
int lastOne = digits[6] % 7;
int firstOne= (digits[0] + (digits[1]*2) + digits[2] + (digits[3]*2) + digits[4] + (digits[5]*2)) % 7;
if(firstOne == lastOne)
{
return true;
}
else
{
return false;
}
}
}
The error is thrown here, line 4
Vehicle::Vehicle(std::string sid, std::string smodel, int syear)
car.h
#include "vehicle.h"
#ifndef CAR_H_INCLUDED
#define CAR_H_INCLUDED
class Car : Vehicle
{
private:
int doors;
bool rightHandDrive;
public:
Car(int sdoors, bool srightHandDrive, std::string sid, std::string smodel, int syear);
};
#endif // CAR_H_INCLUDED
car.cpp
#include "car.h"
Car::Car(int sdoors, bool srightHandDrive, std::string sid, std::string smodel, int syear): Vehicle(sid, smodel, syear){
doors = sdoors;
rightHandDrive = srightHandDrive;
};
I'm pretty new with object-oriented programming and c++. I really tried to search for a solution in a existing thread, but they were pretty different and none of them worked for me. Maybe you can help!