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++ ma
The link error says that the linked cannot find the constructor. The constructor is not in main.cpp, it is in your other file, which is unnamed in your example. Try putting all of it in a single cpp file to get it working.
Here's a good read to understand what's going on when you try to create an executable from source code: How does the compilation/linking process work?
What's going on here is that the linker doesn't know where Person::Person()
, which is being called in main()
, is located. Notice how when you called g++, you never gave it the file where you wrote code for Person::Person()
.
The right way to call g++ is:
$ g++ -o main main.cpp person.cpp