ERROR LNK2019 and ERROR LNK1120 help

This is a discussion on ERROR LNK2019 and ERROR LNK1120 help within the C++ Programming forums, part of the General Programming Boards category; As you are probably aware, these are unresolved external errors. I have a program designed to perform mathematics using a ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    66

    ERROR LNK2019 and ERROR LNK1120 help

    As you are probably aware, these are unresolved external errors. I have a program designed to perform mathematics using a fraction class, and then will utilize a c++ version of the Euclidean algorithm to reduce the fraction to lowest terms by finding the GCD. The fraction.h file will be included below, as well as all of the functions and the function turning up the error.

    The error in question says:
    Code:
    main.obj : error LNK2019: unresolved external symbol "public: int __thiscall fraction::getWholes(void)" (?getWholes@fraction@@QAEHXZ) referenced in function "void __cdecl addFractions(class fraction,class fraction,class fraction)" (?addFractions@@YAXVfraction@@00@Z)
    1>C:\Users\Trey\documents\visual studio 2010\Projects\DS Program 2\Debug\DS Program 2.exe : fatal error LNK1120: 1 unresolved externals
    Here is the .h file.
    Code:
    #pragma onceclass fraction
    {
    private:
        int numerator;
        int denominator;
        int wholes;
    public:
        fraction(void);
        ~fraction(void);
        int getNumerator();
        void setNumerator(int x);
        int getDenominator();
        void setDenominator(int y);
        int getWholes();
        void setWholes(int z);
    };
    Here are the member functions.
    Code:
    fraction::fraction(void){
        numerator = 0;
        denominator = 0;
        wholes = 0;
    }
    
    
    
    
    fraction::~fraction(void)
    {
    }
    
    
    int fraction::getNumerator()
    {
        return numerator;
    }
    
    
    int fraction::getDenominator()
    {
        return denominator;
    }
    
    
    void fraction::setNumerator(int x)
    {
        numerator = x;
        return;
    }
    
    
    void fraction::setDenominator(int y)
    {
        denominator = y;
        return;
    }
    
    
    void fraction::setWholes(int z)
    {
        wholes = z;
        return;
    }
    And last, here is the function turning up the error. I assume that this will carry over into the other functions, so I'll fix it then.
    Code:
    void addFractions(fraction a, fraction b, fraction c){
        //initial output
        cout << a.getNumerator() << "/" << a.getDenominator() << " + " << b.getNumerator() << "/" << b.getDenominator() << " = ";
    
    
        //converts both fractions to like terms
        int j = a.getDenominator();
        int k = b.getDenominator();
        a.setNumerator(a.getNumerator() * k);
        a.setDenominator(a.getDenominator() * k);
        b.setNumerator(b.getNumerator() * j);
        b.setDenominator(b.getDenominator() * j);
    
    
        //arithmetic
        c.setNumerator(a.getNumerator() + b.getNumerator());
        c.setDenominator(b.getDenominator());
    
    
        //reduces to a proper fraction
        if (c.getNumerator() >= c.getDenominator())
        {
            c.setNumerator(c.getNumerator()-c.getDenominator());
            c.setWholes(c.getWholes() + 1);
        }
    
    
        //finds GCD
        int r = euclid(c.getDenominator(), c.getNumerator());
    
    
        //converts to lowest terms with gcd
        c.setDenominator(c.getDenominator()/r);
        c.setNumerator(c.getNumerator()/r);
    
    
        //final output
        if (c.getWholes() != 0)
            cout << c.getWholes() << " " << c.getNumerator() << "/" << c.getDenominator() << "." << endl;
        else if (c.getNumerator() == 0)
            cout << c.getWholes() << "." << endl;
        else
            cout << c.getNumerator() << "/" << c.getDenominator() << "." << endl;
    
    
        return;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The clue is in the message: you never wrote getWholes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-14-2012, 08:22 AM
  2. Replies: 7
    Last Post: 10-27-2012, 02:55 PM
  3. LNK1120 error
    By Shalmander in forum C++ Programming
    Replies: 1
    Last Post: 08-11-2010, 09:21 AM
  4. LNK2019 and LNK1120 Errors?
    By clegs in forum C++ Programming
    Replies: 8
    Last Post: 11-22-2007, 10:46 AM
  5. error LNK1120 & LNK2001:
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2004, 08:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21