Let's look at this part of your code first:
class Token
{
...
public:
...
reservedWords reservedLookup (string tokenString)
{ // start of function body
for(rIt = reservedMap.begin(); rIt!= reservedMap.end(); rIt++)
{
if(tokenString == (rIt->first))
{
return rIt->second;
}
}
} // end of function body
...
};
In this file you have declared a function whose fully-scoped name is Token::reservedLookup
. (If you're unfamiliar with the term "fully scoped", OK; for our purposes here, the important thing is that this is a specific way of naming this function.) We can write Token::
at the front of this name because this function is a member of the class Token
. You have also defined the function by providing a function body (the code enclosed in braces {
and }
). I have added comments on the lines where the function body begins and ends.
So far, so good. Now, this function is an ordinary member of the class Token
, not a "static" function, so in order to call it, you must first have an object of type Token
, and then you can call this function on that object, for example by writing code like this inside some other function:
Token token;
token.reservedDeclare();
reservedWords word = token.reservedLookup("read");
Now comes the part where things get confused. You wrote this code:
class Lexer
{
private:
...
reservedWords reservedLookup(string tokenString);
...
};
What this does is to declare a different function from the first one. This function's fully-scoped name is Lexer::reservedLookup
. You have not provided any definition of the function, however (neither here, nor apparently anywhere else). So when you are within the code of the Lexer
class and you write a line such as this,
tokenType = reservedLookup(strBuffer);
the compiler interprets this in the way the C++ language specification says it should, which is that this should be a call to the function reservedLookup
that belongs to the class of the same function where this call appeared. In short, it is a call to Lexer::reservedLookup
. Since you never defined that function, it is impossible to produce the code that calls the function correctly, and therefore you have an error.
So you probably do not want to define Lexer::reservedLookup
at all. If you are not calling Token::reservedLookup
from within one of the functions of the class Token
itself, you may provide an object of type Token
so that you may call the function, as I did in my example. Alternatively, you might want to make your definition of the function static so that you can call it this way, without requiring an object of type Token
:
reservedWords word = Token::reservedLookup("read");
In order to make this work as desired, however, you would also have to make reservedDeclare
a static function and make reservedMap
a static variable of Token
, or make some other changes so that the data used by Token::reservedLookup
exists independently of a specific object of type Token
.
You may also want to look at the answers to this question: The Definitive C++ Book Guide and List and read a recommended book to help understand the terminology of the language better so that you can get better advice about your programs.