Hi all,
I'm currently working through Programming Principles and Practise and the following code won't compile. I thought it may have been something I have done, but I have since downloaded the source code from Bjarne's site and it still wont compile:
Code:
//
// This is example code from Chapter 6.3.4 "Using tokens" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#include "../std_lib_facilities.h"
//------------------------------------------------------------------------------
class Token {
public:
char kind; // what kind of token
double value; // for numbers: a value
Token(char ch) // make a Token from a char
:kind(ch), value(0) { }
Token(char ch, double val) // make a Token from a char and a double
:kind(ch), value(val) { }
};
//------------------------------------------------------------------------------
Token get_token(); // read a token from cin
//------------------------------------------------------------------------------
vector<Token> tok; // we'll put the tokens here
//------------------------------------------------------------------------------
int main()
{
while (cin) {
Token t = get_token();
tok.push_back(t);
}
// ...
//Now we could find the multiply operation by a simple loop:
for (int i = 0; i<tok.size(); ++i) {
if (tok[i].kind=='*') { // we found a multiply!
double d = tok[i-1].value*tok[i+1].value;
// now what?
}
}
}
//------------------------------------------------------------------------------
The errors I get are:
1>c:\users\darren\documents\visual studio 2008\projects\accelerated c++\accelerated c++\calc3.cpp(39) : warning C4018: '<' : signed/unsigned mismatch
1>Linking...
1>LINK : warning LNK4076: invalid incremental status file 'C:\Users\Darren\Documents\Visual Studio 2008\Projects\Accelerated C++\Debug\Accelerated C++.ilk'; linking nonincrementally
1>Calc3.obj : error LNK2019: unresolved external symbol "class Token __cdecl get_token(void)" (?get_token@@YA?AVToken@@XZ) referenced in function _main
1>C:\Users\Darren\Documents\Visual Studio 2008\Projects\Accelerated C++\Debug\Accelerated C++.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\Darren\Documents\Visual Studio 2008\Projects\Accelerated C++\Accelerated C++\Debug\BuildLog.htm"
1>Accelerated C++ - 2 error(s), 2 warning(s)
Any help would be appreciated.
Thanks.