Thread: Wired errors ??

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    219

    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

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You have a constructor prototyped in the class:
    Code:
    Point();//default Constructor
    But you don't have an implementation. You need something like
    Code:
    Point::Point() {
    }
    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    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 ??

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is the linker that is complaining that it cannot find the implementation of Point().
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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
    Code:
    g++ -c main.cpp
    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 */
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    Ah!
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM