dimanche 31 janvier 2021

Simple C++ Class Undefined symbols for architecture x86_64

I'm new to C++.

Here is my header file:

#ifndef VEHICLE_H
#define VEHICLE_H

class Vehicle {
  protected:
    double S;
  public:
    Vehicle();
};

#endif

and cpp file:

#include "vehicle.h"

Vehicle::Vehicle() 
{
  this->S = 1.00;
}

And this is main.cpp:

#include "vehicle.h"

int main()
{
  Vehicle vehicle;
}

This is a super simple setup, but when I try to run on VSCode with my Mac, I"m getting:

Undefined symbols for architecture x86_64:
  "Vehicle::Vehicle()", referenced from:
      _main in main-9af6ab.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any help appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire