Hello Everyone. I am trying to work through an example cpp program that uses exception handling to detect non-number user entries, but am stuck on a few LNK errors.
The errors are as followed (tied together I believe):
Can anyone tell me what is going on? My file is coded below:
numberverifier.cpp
Any help as always is much appreciated!
I'm still stumbling through the basics of C++
I professionally develop in .NET so C++ is not being all that cooperative with me.
The errors are as followed (tied together I believe):
- error LNK2001: unresolved external symbol "public: virtual int__thiscall NonNumber::What(void)" (?What@NonNumber@@UAEHXZ)
- error LNK1120: 1 unresolved externals.
Can anyone tell me what is going on? My file is coded below:
numberverifier.cpp
// numberverifier.cpp
#include <iostream>
#include <cmath>
#include <string>
#include <stdexcept>
using namespace std;
// class NonNumber definition
class NonNumber : public runtime_error
{
public:
// constructor
NonNumber()
: runtime_error( "non-integer detected" )
{
// empty
} // end class NonNumber definition
virtual int What();
private:
string message;
}; // end class NonNumber
// function castInput definition
int castInput( string input )
{
int result = 0;
int negative = 1;
// check for minus sign
if ( input[ 0 ] == '-' )
negative = -1;
for ( int i = input.length() - 1, j = 0; i >= 0; i--, j++ )
{
if ( negative == -1 && i == 0 )
continue;
if ( input[ i ] >= '0' && input[ i ] <= '9' )
result += static_cast< int >( input[ i ] - '0' ) * pow( 10.0, j );
else
throw NonNumber();
} // end for
return result * negative;
} // end function castInput
int main()
{
string input;
int convert;
cout << "Please enter a number (end-of-file to terminate): ";
while ( cin >> input )
{
try
{
convert = castInput(input);
cout << "The number entered was: " << convert << endl;
} // end try
catch (NonNumber &e)
{
cout << "INVALID INPUT: " << e.What() << endl;
} // end catch
cout << "\n\nPlease enter a number (end-of-file to terminate): ";
} // end while
cout << endl;
} // end main
Any help as always is much appreciated!