繁体   English   中英

收到错误LNK2019和错误LNK1120

[英]Getting errors LNK2019 and error LNK1120

我似乎无法弄清楚为什么我总是收到这两个错误。 我想我没有正确地在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){
}

getTokenTokens的成员,因此在定义它时,需要告诉编译器您正在定义成员函数,而不是独立函数。

在定义getToken函数的主文件中,将其定义为类的一部分,如下所示:

Tokens::TokenType Token::getToken(istream*br, string& lexeme){

尽管我不确定为什么当您有一个名为“ GetTokens.cpp”的文件时,为什么要在主目录中使用它。 考虑将整个内容移至“ GetTokens.cpp”

当前,在“ GetTokens.cpp”中,该函数具有另一个返回void的定义。 摆脱这一定义,因为您只需要一个定义。

LNK2019是链接错误,是一个尚未解决的符号,到目前为止尚未指定。 请编辑您的问题以包括编译输出,以便我们为您提供帮助。

您的IDE是Visual Studio,对不对? 您将需要编辑项目属性以指定源代码文件之间的依赖关系。 未指定的依赖性导致LNK2019链接错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM