I have 3 files with the following definitions
car.h
namespace vehicle {
class Car {
public:
int wheels;
char color[];
void showInfo();
Car(int wheels) {
this->wheels = wheels;
}
};
}
car.cpp
#include <iostream>
#include "car.h"
using namespace vehicle;
using namespace std;
void Car::showInfo() {
cout << this->wheels << endl;
}
prog.cpp (this imports and utilises the above-defined class)
#include "car.h"
using namespace vehicle;
int main() {
Car c(4);
c.showInfo();
return 0;
}
After compiling with g++ prog.cpp this is the error I am getting
/usr/bin/ld: /tmp/ccKlIJ5B.o: in function main': prog.cpp:(.text+0x34): undefined reference to
vehicle::Car::showInfo()'
collect2: error: ld returned 1 exit status