I have been getting this error for my project and I can't figure out why I am getting it. While this is a common error, none of the other posts seem to have the correct solution.
Can't figure out this error:
Main function: (proj5.cpp)
#include <iostream>
#include "Vehicle.h"
#include "Car.h"
using namespace std;
int main(void){
cout << "\n" <<
"////////////////////////////\n" <<
"///// Base Tests /////\n" <<
"////////////////////////////" << endl;
cout << endl << "Testing Base Default ctor" << endl;
Vehicle v1;
cout << endl << "Testing Base insertion operator" << endl;
cout << v1 << endl;
cout << "Base idgen: " << Vehicle::getIdgen() << endl;
cout << endl << "Testing Base Parametrized ctor" << endl;
float lla_rno[3] = {39.54, 119.82, 4500.0};
Vehicle v99(99, lla_rno);
cout << v99 << endl;
cout << "Base idgen: " << Vehicle::getIdgen() << endl;
cout << endl << "Testing Base Copy ctor" << endl;
Vehicle v99_cpy( v99 );
cout << v99_cpy << endl;
cout << "Base idgen: " << Vehicle::getIdgen() << endl;
cout << endl << "Testing Base Assignment operator" << endl;
v1 = v99_cpy;
cout << v1 << endl;
cout << "Base idgen: " << Vehicle::getIdgen() << endl;
cout << endl << "Testing Base Move Function" << endl;
float lla_new[3] = {37.77, 122.42, 52.0};
v1.move( lla_new );
cout << "\n" <<
"////////////////////////////\n" <<
"///// Derived Tests /////\n" <<
"////////////////////////////" << endl;
cout << endl << "Testing Derived Default ctor" << endl;
Car c1;
cout << endl << "Testing Derived insertion operator" << endl;
cout << c1 << endl;
cout << "Derived idgen: " << Car::getIdgen() << endl;
cout << endl << "Testing Derived Parametrized ctor" << endl;
char plates_999[] = "Gandalf";
Car c999(plates_999, 999, lla_rno);
cout << c999 << endl;
cout << "Derived idgen: " << Car::getIdgen() << endl;
cout << endl << "Testing Derived Copy ctor" << endl;
Car c999_cpy( c999 );
cout << c999_cpy << endl;
cout << "Derived idgen: " << Car::getIdgen() << endl;
cout << endl << "Testing Derived Assignment operator" << endl;
c1 = c999_cpy;
cout << c1 << endl;
cout << "Derived idgen: " << Car::getIdgen() << endl;
cout << endl << "Testing Derived Move Function" << endl;
c1.move( lla_new );
cout << "\n" <<
"////////////////////////////\n" <<
"///// Tests Done /////\n" <<
"////////////////////////////" << endl;
return 0;
}
Car.cpp:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Car.h"
#include "Vehicle.h"
using namespace std;
Car::Car()
{
m_throttle = 0;
const int m_vin = getIdgen();
m_lla = (float*)malloc(sizeof(float) * 3);
cout << "Car #" << m_vin << ": Default-ctor" << endl;
}
Car::Car(char * plates, int vin, float * lla)
{
strcpy(m_plates, plates);
const int m_vin = *vin;
for(int i = 0; i < 3; i++)
{
m_lla[i] = lla[i];
}
cout << "Car # " << m_vin <<": Parametrized-ctor" << endl;
}
Car::Car(Car & old)
{
const int m_vin = old.getVin();
strcpy(m_plates, old.getPlates());
setLLA(*(old.getLLA()));
cout << "Car #" << m_vin << ": Copy-ctor" << endl;
}
Car::~Car()
{
cout << "Car #" << m_vin << ": Dtor" << endl;
}
char * Car::getPlates()
{
return m_plates;
}
void Car::operator=(Car & car)
{
this->m_throttle = getThrottle();
strcpy(this->m_plates, car.getPlates());
const int m_vin = car.getVin();
this->m_lla = car.getLLA();
cout << "Car #" << m_vin << ": Assignment" << endl;
}
int Car::getThrottle()
{
return m_throttle;
}
void Car::setThrottle(int num)
{
m_throttle = num;
}
void Car::setPlates(char * plates)
{
strcpy(m_plates, plates);
}
void Car::drive(int * num)
{
m_throttle = *num;
}
void Car::move(float * lla)
{
this->setLLA(*lla);
cout << "Car #" << m_vin << ": DRIVE to destination, with throttle @ 75" << endl;
}
Car.h: #
ifndef CAR_H_
#define CAR_H_
#include "Vehicle.h"
class Car: public Vehicle
{
public:
Car();
Car(char * plates, int vin, float * lla);
Car(Car & old);
~Car();
void operator=(Car & car);
char * getPlates();
int getThrottle();
void setPlates(char * plates);
void setThrottle(int throttle);
void drive(int * throttle);
void move(float * lla);
private:
char * m_plates;
int m_throttle;
};
#endif
Here is the error:
/tmp/cczSuMnH.o: In function main':
proj5.cpp:(.text+0x3bd): undefined reference to
Car::Car()'
proj5.cpp:(.text+0x487): undefined reference to Car::Car(char*, int, float*)'
proj5.cpp:(.text+0x50e): undefined reference to
Car::Car(Car&)'
proj5.cpp:(.text+0x595): undefined reference to Car::operator=(Car&)'
proj5.cpp:(.text+0x61f): undefined reference to
Car::move(float*)'
proj5.cpp:(.text+0x673): undefined reference to Car::~Car()'
proj5.cpp:(.text+0x67f): undefined reference to
Car::~Car()'
proj5.cpp:(.text+0x68b): undefined reference to Car::~Car()'
proj5.cpp:(.text+0x6da): undefined reference to
Car::~Car()'
proj5.cpp:(.text+0x6eb): undefined reference to Car::~Car()'
/tmp/cczSuMnH.o:proj5.cpp:(.text+0x6fc): more undefined references to
Car::~Car()' follow
collect2: error: ld returned 1 exit status