Thread: Recursive function gives undefined reference bug

  1. #1
    Registered User
    Join Date
    Dec 2010

    Recursive function gives undefined reference bug

    The following section of my code is giving me problems (cout statements removed to save space):

      int CSP;
      void allocatecsp (); {
      cin >> CSP;
      cin >> sws;
      CSP = CSP - sws;
      cin >> axs;
      CSP = CSP - axs;
      cin >> sps;
      CSP = CSP - sps;
      cin >> bos;
      CSP = CSP - bos;
      cin >> shs;
      CSP = CSP - shs;
      int cspreallocate;
      if (CSP > 0) {
            cin >> cspreallocate;
            if (cspreallocate = 0) {
                allocatecsp ();     //  ********************
      else if (CSP < 0) {
           allocatecsp ();  // ********************
      else {
            cin >> cspreallocate;
            if (cspreallocate == 0) {
            allocatecsp (); // ********************
    When I try to compile, it returns "undefined reference to 'allocatecsp()'" error in the lines marked with stars. Any idea why this would be (all variables not declared here are declared above the top)?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    void allocatecsp (); {
    should be:
    void allocatecsp () {
    This line looks like it has another mistake:
    if (cspreallocate = 0) {
    Furthermore, avoid the use of global variables, and although you made a good attempt at indentation, it could still be improved.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference to functions, that CAN be found
    By Carola in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2009, 05:59 AM
  2. undefined reference to function names
    By hellogamesmaste in forum C Programming
    Replies: 5
    Last Post: 08-17-2009, 03:05 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Textbox
    By maxorator in forum Windows Programming
    Replies: 20
    Last Post: 09-25-2005, 10:04 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM