我正在尝试构建一个程序来Tolkinize一个字符串(我试图在不使用字符串类的情况下做到这一点 - 以便了解有关指针和字符如何工作的更多信息) - 我已经构建了一个我认为有效的程序(任何建议会很棒!)当我尝试编译程序时,我得到了这些随机错误:
错误 1 错误 LNK2019:函数 _main 驱动程序中引用的未解析外部符号“public: char * __thiscall Tokenize::next(void)”(?next@Tokenize@@QAEPADXZ)
错误 2 错误 LNK2019:函数 _main Driver 中引用的未解析外部符号“public: __thiscall Tokenize::Tokenize(char const * const,char)”(??0Tokenize@@QAE@QBDD@Z)
错误 3 致命错误 LNK1120: 2 unresolved externals C:\Users\Simmons 2.0\Documents\School\CS1410\project 5\Token\Debug\Token.exe
我已经向几个朋友展示了这段代码,他们都不知道发生了什么——或者我做错了什么……
注意:我正在运行 VS 2008 express edition - Windows 7 x64主文件
#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;
}
标记化.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
标记化.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;
}
};
根据我的测试(注释掉行),我认为其中一个错误来自tokinze.next()