Calling a function from a header to another header

So I'm doing a compiler, and I'm using writing everything in headerfiles.

at the moment I have lexer.h, token.h and for this case I need reservedWords.h

reservedWords.h is made up of enums showing the needed words

in token.h I have a function called reservedWords reservedLookup(string str) which returns a reservedWord (enum)

now in lexer.h I have a function called Token* getNextToken() in which I need to make use of the function reservedLookup found in token.h

please not that all of them are classes apart from reservedwords as in

1
2
3
4
5
6
7
8
9
class Lexer
{
   public: .....
}

class token
{
    public .....
}



Any idea how I can call that function?

I tried declaring reservedWords reservedLookup (string str) BUT obviously it's directing me as Lexer::reservedLookup and not as Token::reservedLookup

When I tried using Token::reservedLookup it gave m
e
E:\University\compilers\lexer.h|65|error: cannot declare member function 'Token::reservedLookup' within 'Lexer'|

Any help please?

N.B I use namespace std, that's why I didnot write std::string str

thx
Last edited on
I'm using writing everything in headerfiles.


The problem you've run into is exactly why we have separate header and code files. Declare your classes in a header file, implement them in a code file.
Topic archived. No new replies allowed.