Thread: Stroustrup Chapter 6 class Token Example Link Error

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    2

    Stroustrup Chapter 6 class Token Example Link Error

    Hello everyone, I'm having a linking error with:
    Code:
    #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();  // PROBLEM MAY BE HERE
    
    //------------------------------------------------------------------------------
    
    vector<Token> tok;    // we'll put the tokens here
    
    //------------------------------------------------------------------------------
    
    int main()
    {
    
        while (cin) {
            Token t = get_token();
            tok.push_back(t);
        }
        // ...
        
    
        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?
            }
        }
    }
    Getting:
    1>D:\Documentos\Projectos\Programming P & P w C++\Libro\6.3 Example Tokenizing\Debug\6.3 Example Tokenizing.exe : fatal error LNK1120: 1 unresolved externals
    1>
    1>Build FAILED.

    Pleas advise
    Last edited by Salem; 02-16-2011 at 01:26 PM. Reason: Added [code][/code] tags - learn to use them yourself

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It should have given you a list of the unresolved symbols.

    And yes, you will need to implement get_token().
    It isn't enough just to state that it exists.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    2
    Hello there!

    It results that the entire chapter leads you to inminent error!

    He does a lot of unexplained implementations because he is not WRITING the program, he is thinking it. STILL, I did not get that until the last part of the chapter, where STILL I don't get the entire flow of the program.

    Whoever read the chapter, will agree that the grammar implementation with the tokenize input (which all that implies - returning the token to the stream after unused evaluations & stuff) is complicated to grasp at first glance.

    Basically, at the end of the chapter we have:

    class Token - tokenizer
    class ts - fetches and returns tokens from i/o streams
    double expression();
    double term();
    double primary();
    int main();

    The process of how to achieve "correctesness" is impressively weel explained, but the program itself it may not be the best example just because of the classes implementations with constructors which I don't fully understand.

    Thanks a bunch!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM