Some errors cannot be detected by the compiler. As far as the compiler can tell, Point() has a Point() default constructor which takes no parameters, because you've declared it as such. It doesn't find the implementation of Point::Point(), but it's not too worried because it could be in a different source file. If you have different source files, you oculd so this:
Code:
/* one.cpp */
int square(int x) {
return x * x;
}
Code:
/* main.cpp */
#include <iostream>
/* this is the prototype, equivalent to your declaration of Point() inside the class.
It tells the compiler that this does in fact exist somewhere, and even though it
can't find the implementation of this function, compile on. */
int square(int x);
int main() {
std::cout << square(3) << std::endl;
return 0;
}
Now when you compile main.cpp with
it compiles. But when you link your program, you have to add square.o as well, or else the linker won't be able to find square().
Code:
g++ -c main.cpp
g++ -c square.cpp
g++ -o test.exe main.o square.o /* works */
g++ -o test.exe main.o /* fails */