Thread: Error LNK2019: unresolved external symbol

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    7

    Error LNK2019: unresolved external symbol

    I've been searching for an hour and can't figure out what's wrong. I tried moving it to a new project, but that didn't fix it.

    Here is the error message:
    Lab09.cpp
    InputNumber.obj : error LNK2019: unresolved external symbol "public: bool __thiscall InputNumber::valInput(void)" (?valInput@InputNumber@@QAE_NXZ) referenced in function "public: void __thiscall InputNumber::setNum(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setNum@InputNumber@@QAEXV?$basic_string@DU?$char _traits@D@std@@V?$allocator@D@2@@std@@@Z)
    C:\Users\Sarah\Desktop\Lab 9\Debug\Lab 9.exe : fatal error LNK1120: 1 unresolved externals

    And here is my code (1 header and 2 .cpp):

    Lab09.cpp
    Code:
    //Testing InputNumber
    #include <iostream>
    #include <string>
    #include <cstring>
    #include "InputNumber.h"
    using namespace std;
    
    
    int main()
    {
        InputNumber num;
        
        cout << "Type a number: ";
        num.input();
        cout << "You typed " << num.getInString() << endl;
        
        if(num.validInputValue())
        {
            cout << "What you typed has numeric value " << num.getValue() << endl;
            cout << "Your number with commas is " << num.commaString() << endl;
        }
        else
            cout << "What you typed is not a valid numeric value. " << endl;
        return 0;
    }
    InputNumber.cpp
    Code:
    //Class implementation file
    #include "InputNumber.h"
    
    
    //Declaring and Initializing New Object
    InputNumber::InputNumber()
    {
        inString = "0";
        validInput = true;
        numValue = 0;
    }
    
    
    InputNumber::InputNumber(long newNumValue)
    {
        setNum(newNumValue);
    }
    
    
    InputNumber::InputNumber(string newInString)
    {
        setNum(newInString);
    }
    
    
    
    
    //Get Functions
    long InputNumber::getValue()
    {
        return numValue;
    }
    
    
    std::string InputNumber::getInString()
    {
        return inString;
    }
    
    
    bool InputNumber::validInputValue()
    {
        return validInput;
    }
    
    
    
    
    std::string InputNumber::commaString()
    {
        if (validInput = true)
            {
                string comString = inString;
                int length = comString.length();
    
    
                int i = (comString.length() - 3);
                while (i > 0)
                {
                    comString.insert(i, 1, ',');
                    i = i - 3;
                }
    
    
                return comString;
            }
            
    }
    
    
    void InputNumber::input()
    {
        string tempString;
        getline(cin, tempString);
        setNum(tempString);
    }
    
    
    void InputNumber::setNum(long newNum)
    {
        numValue = newNum;
    
    
        validInput = true;
    
    
        char cInString[20];
        itoa(newNum, cInString, 0);
        inString = cInString;
    
    
        return;
    }
    
    
    void InputNumber::setNum(std::string strNum)
    {
        inString = strNum;
    
    
        validInput = valInput();
    
    
        int size = inString.size();
        char cInString[20];
        strcpy(cInString, inString.c_str());
        numValue = atol(cInString);
    
    
        return;
    }
    InputNumber.h
    Code:
    //Class header file
    #include <string>
    #include <iostream>
    using namespace std;
    #ifndef INPUTNUMBER_H
    #define INPUTNUMBER_H
    
    
    class InputNumber
    {
    
    
    private:
    
    
        std::string inString;
        bool validInput;
        long numValue;
     
    public:
    
    
        InputNumber();
    
    
        InputNumber(long);
          
        InputNumber(std::string);
    
    
    
    
    
    
        long getValue();
           
        std::string getInString();
     
        bool validInputValue();
    
    
        std::string commaString();
    
    
        void input();
    
    
        void setNum(long);
    
    
        void setNum(std::string);
        
        bool valInput();
    };
    
    
    #endif

  2. #2
    Registered User
    Join Date
    Oct 2012
    Posts
    7
    Please help? This post has lots of views but no replies. I really need input.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I really need input.
    Cannibalope = getchar();



    Seriously, though, I don't know anything about C++, so I personally can hardly look at your code and see what's wrong. However, I do have something here I like to call the internet. I found a site talking about a similar linker error. I might be completely wrong, but shouldn't the "bool valInput()" function be defined in your "inputNumber.cpp" file?

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    It's exactly what the message says: it can't find the implimentation of valInput(). I don't see it in your code either. It declared in the header, but never defined.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error LNK2019: unresolved external symbol
    By kiros88 in forum C++ Programming
    Replies: 7
    Last Post: 06-16-2010, 01:16 PM
  2. Help with: error LNK2019: unresolved external symbol
    By darren78 in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2010, 06:26 AM
  3. error LNK2019: unresolved external symbol
    By Warlax in forum C++ Programming
    Replies: 8
    Last Post: 12-09-2008, 01:37 PM
  4. error LNK2019: unresolved external symbol
    By Opel_Corsa in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2006, 12:12 PM
  5. Replies: 3
    Last Post: 06-16-2006, 05:48 AM