我似乎无法弄清楚为什么我一直得到这两个错误。我想我没有在HTMLlexicalSyntax.cpp中正确地引用getToken(br,track)函数,但我不确定如何修复它。
这是它给我的错误。
1>HTMLlexicalSyntax.obj : error LNK2019: unresolved external symbol "enum Tokens::TokenType __cdecl getToken(class std::basic_istream<char,struct std::char_traits<char> > *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?getToken@@YA?AW4TokenType@Tokens@@PAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z) referenced in function _main
1>C:\Users\John\Documents\College\CS 280\FALL 2014\HTML LEXICAL SYNTAX\Debug\HTML LEXICAL SYNTAX.exe : fatal error LNK1120: 1 unresolved externals
这是我的头文件。
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <istream>
#include <ostream>
#include <string>
class Tokens
{
public:
enum TokenType {
TEXT,
LANGLE,
RANGLE,
SLASH,
ID,
EQ,
QSTRING,
OTHER,
END,
};
Tokens getToken(std::istream*br, std::string&lexeme);
};
HTMLlexicalSYNTAX.cpp
#include "stdafx.h"
#include "TOKENS.h"
#include <iostream>
#include <fstream>
#include <istream>
#include <ostream>
#include <string>
using namespace std;
我的int main(int argc,char * argv [])中的内容:
Tokens::TokenType getToken(istream*br, string& lexeme);{
while(br->good()){
getline(*br, track);
while (!looking){
if(track == "/0"){
looking = true;
}
else {
spot = track.find("\n");
if (spot == -1){
looking = true;
spot = track.length();
}
track = track.substr(0, spot);
getToken(br, track);
}
}
}
}
GetTokens.cpp
#include <iostream>
#include <fstream>
#include <istream>
#include <ostream>
#include <string>
#include "TOKENS.h"
using namespace std;
void getToken(istream*br, string& lexeme){
}
答案 0 :(得分:0)
getToken
是Tokens
的成员,所以当你定义它时,你需要告诉编译器你正在定义成员函数,而不是一个独立的函数。
在定义getToken
函数的主文件中,将其定义为类的一部分,如下所示:
Tokens::TokenType Token::getToken(istream*br, string& lexeme){
虽然当你有一个名为“GetTokens.cpp”的文件时,我不确定你为什么要使用它。考虑将整个事情移到“GetTokens.cpp”
答案 1 :(得分:0)
LNK2019是一个链接错误,一个未解析的符号,到目前为止尚未指定。请编辑您的问题以包含编译输出,以便我们为您提供帮助。
您的IDE是Visual Studio,对吗?您需要编辑项目属性以指定源代码文件之间的依赖关系。未指定的依赖项会导致LNK2019链接错误。