Exception Handling

I'm getting a LNK2001 error that I'm not sure how to resolve. I was hoping I could get a point in the right direction. Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// numberverifier.cpp
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <cmath>
#include <cstring>

class nonNumber { 
public:
   nonNumber()
      : message( "non-integer detected" ) { }
   /* write definition for method what */
   virtual int what();

private: 
   const char *message;
};

int castInput( char *s )
{
   char *temp = s;
   int result = 0, negative = 1;

   // check for minus sign
   if ( temp[ 0 ] == '-' )
     negative = -1;

   for ( int i = strlen( s ) - 1, j = 0; i >= 0; i--, j++ ) {
         
      if ( negative == -1 && i == 0 )
         continue;

      if ( isdigit( temp[ i ] ) )
		result += ( temp[ i ] - '0' ) * pow( 10.0, j );   
      else 
         /* write code to throw nonNumber exception */
		throw nonNumber();

   }

   return result * negative;
}

int main()
{
   char input[ 100 ];
   int convert; 
   cout << "Please enter a number (EOF to end): ";

   while ( cin >> input ) 
   {

      /* write try block that calls castInput */
      /* write catch statement that catches any exceptions
         that the call to castInput might have thrown */
	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 (EOF to end): ";
   }

   cout << endl;
   return 0;
}


Here's the error message:

Linking...
1>nonNumber.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall nonNumber::what(void)" (?what@nonNumber@@UAEHXZ)
1>C:\Documents and Settings\A. Rowe\My Documents\Visual Studio 2008\Projects\ErrorException\Debug\ErrorException.exe : fatal error LNK1120: 1 unresolved externals


Thanks for your help,
airowe
Topic archived. No new replies allowed.