I want to emit dynamic error messages like all interpreters do nowadays, for example:
Name error: Undefined variable
would be constant, however what I want to reach is:
Name error: Undefined variable 'X', in line 1
Okay. The line number was really no problem: Every error message must have a line number, so I added it to the error emitter function:
Error( ErrType type, string msg, int line );
So where is my problem?
How do I get the 'X'
into Undefined variable *
?
- I can't use sprintf as it doesn't support strings yet I use them everywhere
- I can't simply use cout and connect everything as I want error messages to be supressable
- I'd like to get everything into one function like above,
Error()
How do I put together dynamic error messages?
For example: Error( Name, sprintf("Undefined variable %s", myVariableName ), lineNum );
(But myVariableName
is a string and sprintf
will mess things up)