Several files in C++

While following Ivan’s video, I tried running the same code that he did. My cpp file looks like this:

#include<iostream>

#include "car.h"

using namespace std;

void Car::blowHorn()
{
    cout<<"BLOWING HORN!!!";
}

Car::Car()
{
    
}
Car:: ~ Car()
{
    
}

the line “Car::~Car()” has an error message that says “definition of implicitly declared destructor”

In the video, I van said that we haven’t covered that yet, and we shouldn’t worry about it. Well, My machine won’t run the program because of it. Any advice? I am using xcode 12. I just updated last night.

Hey @dani88 :slight_smile:

You should wrap your methods in a class:

class Car {
  /* Your methods here */
}
1 Like

in the video the class was put in the car.h file. This file that I gave you was the deconstruct command placed in the Car.cpp file Here is the header file:



#ifndef car_h
#define car_h


class Car
{
    public:
        Car();
    
        virtual
        void blowHorn();
    
    protected:
    
    
    private:
    
};

#endif /* car_h */

Oh sorry, I wasn’t careful, you forgot to define the destructor in the header file. :slight_smile:

class Car
{
    public:
        Car();
        ~Car(); // Add this in header.
    
        virtual void blowHorn();
};
1 Like

My fault, I didn’t give you all the information. Thanks for your help. It was in the video, I just need to pay closer attention to details.

1 Like