Tokens (get_token error)

I'm on chapter 6.34 of "Programming: Principles and Practice Using C++" by Bjarne.
Anyways, i'm learning about tokens and how to use them. It's all confusing, rushed, and just thrown at the reader (me), but it's ok. i'm grasping the concept and the need of them to complete the "calculator" program. I usually just follow along and just write the code into my compiler and follow along, getting the errors that the book intends us to get and then fix them. However, when i was writing out the Token code I get the error "Apple Mach-O linker (ld) Error "get_token reference()" reference" "Undefined symbols for architecture x86_64:
"get_token()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)"

... I have no idea of what this means. or how to fix it. can any one help me?

Btw, i'm coding with a Macbook, using xCode as my compiler. Does my machine have anything to do with this?

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
  #include<iostream>
#include<istream>
#include<fstream>
#include "std_lib_facilities.h"
using namespace std;


class Token{
public:
    char kind;
    double value;
    Token(char ch)
    :kind(ch),value(0){}
    Token(char ch, double val)
    :kind(ch), value(val){}
};
Token get_token();
vector<Token>tok;

int main()
{
    while (cin){
        Token t=get_token();
        tok.push_back(t);
    }
}
closed account (3hM2Nwbp)
At line 17, the function is declared, but is never defined anywhere (that can be seen from what you've posted). When the linker looks for the definition, it can't find it and complains.

 
Token get_token(); // Declared, but not defined. 


1
2
3
4
5
6
7
8
9
Token get_token(); // Declared

//...
//...

Token get_token() // Defined
{
  //...
}


1
2
3
4
Token get_token() // Declared and defined
{
  //...
}


Standard wrote:

A declaration introduces names into a translation unit or redeclares names introduced by previous declarations. A declaration specifies the interpretation and attributes of these names.


A declaration is also classified as a definition unless:
1) It doesn't provide a function body
2) It's a class declaration and declares one or more static members
3) It's a class name declaration
4) It is declared as extern without an initialization statement or function body
5) It's a typedef statement
6) It's a 'using' statement (including 'using namespace')

You can have at most one definition per declaration, per translation unit (One Definition Rule).

Standard wrote:
No translation unit shall contain more than one definition of any variable, function, class type, enumeration type, or template.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
Token get_token(); // Declaration

Token get_token() // Definition
{

}

//...
//...

Token get_token() // Error - multiple definitions for declared function 'get_token'
{

}
Last edited on
Topic archived. No new replies allowed.