-
Wired errors ??
Here I've Pasted My very Small ammount of Codes http://phpfi.com/246165
I am getting this Errors what does it mean ?? Code:
/tmp/ccRTY7b3.o: In function `main':
op_overload.cpp:(.text+0xb7): undefined reference to `Point::Point()'
collect2: ld returned 1 exit status
Please help
-
You have a constructor prototyped in the class:
Code:
Point();//default Constructor
But you don't have an implementation. You need something like
like you have the copy constructor:
Code:
Point::Point(int a, int b){
Alternatively, you could just go
Code:
Point() {} //default Constructor
inside the class.
-
Thanks I've changed te Constructor Blocks to this Code:
Point(){}//default Constructor
Point(int, int);//Constructor
Point(const Point&);//Copy Constructor
And its workin Now
But What does the error Mean ??
Why Its getting Compiled to op_overload.o with -c if it has Errors ??
-
It is the linker that is complaining that it cannot find the implementation of Point().
-
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 */
-