I am trying to build a program to Tolkinize a string (i’m trying to do this with out using the string class – so as to learn more about pointers and how chars work) – I have built a program that i think works (any suggestions would be great!) When i tried to compile the program I get these random errors:
Error 1 error LNK2019: unresolved external symbol “public: char * __thiscall Tokenize::next(void)” (?next@Tokenize@@QAEPADXZ) referenced in function _main Driver
Error 2 error LNK2019: unresolved external symbol “public: __thiscall Tokenize::Tokenize(char const * const,char)” (??0Tokenize@@QAE@QBDD@Z) referenced in function _main Driver
Error 3 fatal error LNK1120: 2 unresolved externals C:\Users\Simmons 2.0\Documents\School\CS1410\project 5\Token\Debug\Token.exe
I have showed this code to a couple of friends that code and none of them could figure out what is going on – or what i’m doing wrong…
Note: I am running VS 2008 express edition – Windows 7 x64
Main.cpp
#include <iostream>
#include "tokenize.h" /// Tolkenize class
using namespace std;
int main ( )
{
// create a place to hold the user's input
// and a char pointer to use with the next( ) function
char words[128];
char * nextWord;
cout << "\nString Tokenizer Project";
cout << "Enter in a short string of words:";
cin.getline ( words, 127 );
// create a tokenizer object, pass in the char array
// and a space character for the delimiter
Tokenize tk( words, ' ' );
// this loop will display the tokens
while ( ( nextWord = tk.next() ) != NULL ) {
cout << nextWord << endl;
}
system("PAUSE");
return 0;
}
tokenize.h
#include <iostream>
#include <cassert> /// assert
#include <cstdlib> /// system("cls")
using namespace std;
#ifndef TOKENIZE_H
#define TOKENIZE_H
#include <iostream>
#include <cassert>
#include "Tokenize.h"
using namespace std;
class Tokenize {
private:
char * current_ptr;
char delimiter;
public:
Tokenize ();
Tokenize (char);
Tokenize (char const string [], char Delimiter);
void setcurrent_ptr ( char * ptr ){ current_ptr = ptr; }
void setdelimiter ( char Delimiter ) { delimiter = Delimiter; }
char * getcurrent_ptr () { return current_ptr; }
char getdelimiter () { return delimiter; }
char * next ();
};
#endif
tokenize.cpp
#include <iostream>
#include <cassert> /// assert
#include "Tokenize.h"
using namespace std;
Tokenize::Tokenize() {
current_ptr = new char;
*current_ptr = NULL;
delimiter = ' ';
};
Tokenize::Tokenize(char Delimiter) {
current_ptr = new char;
*current_ptr = NULL;
delimiter = Delimiter;
};
Tokenize::Tokenize(char const string [], char Delimiter) {
current_ptr = string;
delimiter = Delimiter;
};
char * Tokenize::next() {
char * ptr = current_ptr;
If ( (*ptr) == NULL ) { return NULL; }
else {
while ((current_ptr)++ != ' ') {}
if ( (*current_ptr) == NULL) { return NULL; }
if ( *current_ptr == ' ' ) { *current_ptr = '/0'; (current_ptr)++; }
return ptr;
}
};
From my testing (commenting out lines) I think one of the errors come from the tokinze.next()
It looks like you’re not compiling/linking tokenize.cpp.
It’s probably not the code itself, but how you have it setup in Visual Studio.
Is it possible that VS isn’t including tokenize.cpp in your application?
You can test that this is the problem by moving the functions from tokenize.cpp to main.cpp. If the errors go away, that’s the problem.