I'm attempting to link my .cpp implementation file with my header file - I get this error message from my mac terminal -
rowlandev:playground rowlandev$ g++ main.cpp -o main
Undefined symbols for architecture x86_64:
"Person::Person()", referenced from:
_main in main-32e73b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is the code in my cpp file:
#include <iostream>
#include "playground.h"
using namespace std;
Person::Person() {
cout << "this is running from the implementation file" << endl;
}
here is the code with my main function:
#include <iostream>
#include "playground.h"
using namespace std;
int main() {
Person chase;
}
and here is the code in my header file:
#include <string>
using namespace std;
#ifndef playground_h
#define playground_h
class Person {
public:
Person();
private:
string name;
int age;
};
#endif /* playground_h */
what should I do to fix this error? Feel free to add any other things I can do to improve the code I just wrote. Open to anything.