Source code not compiling...

This is a discussion on Source code not compiling... within the C++ Programming forums, part of the General Programming Boards category; Hi all, I'm currently working through Programming Principles and Practise and the following code won't compile. I thought it may ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    329

    Source code not compiling...

    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.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,648
    Perhaps you are missing or somehow did not compile the file that contains the definition of the get_token() function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Quote Originally Posted by laserlight View Post
    Perhaps you are missing or somehow did not compile the file that contains the definition of the get_token() function.
    Hasn't that been declared by:

    Token get_token();

    According to the book this should compile?

    Thanks.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,648
    Quote Originally Posted by darren78
    Hasn't that been declared by:

    Token get_token();
    But, but it also has to be defined (implemented) somewhere.

    Quote Originally Posted by darren78
    According to the book this should compile?
    And indeed the source file was compiled. What you have is a linker error.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    So, would you say the error is the line:

    Token get_token(); and that should have been where the function was defined?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,648
    No, that is not an error. It may be the case that the function is defined in another source file which you did not include in the project.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Sorted now thanks. The function was included later on.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Documenting Source Code
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 01-04-2008, 11:18 AM
  2. loop and compiling inside a code
    By MtJ in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 11:50 AM
  3. Compression utility source code
    By Blizzarddog in forum C++ Programming
    Replies: 4
    Last Post: 11-07-2003, 07:15 PM
  4. DxEngine source code
    By Sang-drax in forum Game Programming
    Replies: 5
    Last Post: 06-26-2003, 05:50 PM
  5. Lines from Unix's source code have been copied into the heart of Linux????
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-19-2003, 03:50 PM

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