Reputation: 3
I can't seem to figure out why I keep getting these two errors. I think I'm not putting the right referencing to the getToken(br, track) function correctly within HTMLlexicalSyntax.cpp but I'm not sure how to fix it.
This is the error it is giving me.
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
This is my header file.
#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;
Whats within my 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){
}
Upvotes: 0
Views: 327
Reputation: 8514
getToken
is a member of Tokens
, so when you define it you need to tell the compiler that you are defining the member function, rather than a standalone function.
In your main file where you define the getToken
function, define it as part of the class like this:
Tokens::TokenType Token::getToken(istream*br, string& lexeme){
Though I am not sure why you have this in main when you have a file called "GetTokens.cpp". Consider moving the whole thing to "GetTokens.cpp"
in "GetTokens.cpp" you currently have another definition of the function that is returning void. Get rid of this one as you only want one definition.
Upvotes: 0
Reputation: 2036
LNK2019 is a linkage error, an unresolved symbol which is unspecified so far. Please edit your question to include the compilation output so we can help you.
Your IDE is Visual Studio, right? You will need to edit your project properties to specify the dependencies among your source code files. Unspecified dependencies lead to LNK2019 linkage errors.
Upvotes: 0