I do not understand how to compile c++ code correctly. I have a test file using an example class and I continue to get the error:
user@MacBook-Pro Online-Order-OOP-Project % clang++ -std=c++11 -o test.out test.cpp
Undefined symbols for architecture arm64:
“Point::getX()”, referenced from:
_main in test-3f2ef3.o
“Point::Point()”, referenced from:
_main in test-3f2ef3.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It was my understanding that using the #include statements would handle the linking for me. How do I make this compile correctly?
here is the test.cpp file
#include "Point.h"
#include <iostream>
int main() {
Point point;
std::cout << point.getX() << std::endl;
return 0;
}
Here is the Point.h file
#ifndef POINT_H
#define POINT_H
class Point {
private:
int x;
int y;
public:
Point() ;
int getX() ;
int getY() ;
};
#endif
and the Point.cpp file
#include “Point.h”
Point::Point() {
this->x = 0;
this->y = 0;
}
int Point::getX() {
return this->x;
}
int Point::getY() {
return this->y;
} ;