-3

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!

  • 1
    Possible duplicate of [Undefined reference to vtable](https://stackoverflow.com/questions/3065154/undefined-reference-to-vtable); in particular, see [the currently second-highest voted answer](https://stackoverflow.com/a/15113814/9837301). – JaMiT Aug 13 '19 at 23:24
  • you're right, I didn't mention it because my code has thrown the error in the same line the constructor is getting implemented. Should I delete this one? – Michael Göggelmann Aug 13 '19 at 23:34

1 Answers1

0

~Vehicle virtual destructor is declared, but never actually implemented.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85