Thread: Returning values by reference.

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    62

    Returning values by reference.

    I am having some problems with an error I do not understand it looks to me the exact same as in the book. Here is the code and the given error.

    Code:
    Code:
    #include <iostream>
    
    using namespace std;
    enum ERR_CODE {SUCCESS, ERROR};
    ERR_CODE Factor(int, int&, int&); // Function prototype
    
    int main()
    {
        int number, squared, cubed;
        ERR_CODE result;
    
        cout << "Enter a number (0-20): " ;
        cin >> number;
    
        result = Factor(number, squared, cubed);
    
        if(result == SUCCESS)
        {
            cout << "Nunber:\t\t" << number << endl;
            cout << "Squared:\t\t" << squared << endl;
            cout << "Cubed:\t\t" << cubed << endl;
        }
        else
        {
            cout << "Error encountered!!" << endl;
        }
    
        return 0;
    }
    
    ERR_CODE Factor(int n, int rSquared, int rCubed)
    {
        if (n > 20)
        {
            return ERROR; // Simple error code
        }
        else
        {
            rSquared = n*n;
            rCubed = n*n*n;
            return SUCCESS;
        }
    }
    Error:
    Line:15 Undefined reference to 'Factor(int, int&, int&)'

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    ERR_CODE Factor(int, int&, int&); // Function prototype
    
    ...
    
    ERR_CODE Factor(int n, int rSquared, int rCubed)
    The prototype indicates & but the function definition does not.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    62
    Thanks, guess I have been awake for to long.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. returning reference from class
    By l2u in forum C++ Programming
    Replies: 17
    Last Post: 12-16-2007, 11:21 AM
  2. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  3. Textbox
    By maxorator in forum Windows Programming
    Replies: 20
    Last Post: 09-25-2005, 10:04 AM
  4. How to: Use OpenGL with Jgrasp
    By Pickels in forum Game Programming
    Replies: 3
    Last Post: 08-30-2005, 10:37 AM
  5. Returning reference to STL String class
    By frisbee in forum C++ Programming
    Replies: 5
    Last Post: 12-29-2003, 12:39 PM