Global variable problem (function related)
Hello.
I'm trying to create some kind of error system but I fail and I'm asking if one of you could help me. Here's the deal:
When one of my functions is about to return FALSE (or -1) I'll make it call a SetError function first (with a string as paramater).
When the programs notice that the function returns FALSE it will then call the GetError function and display the error to the user.
My question: How could I create this without using a global variable?
Here is a simple code example where I hope you see what I mean:
Code:
//In "Error.hpp"
# include <windows.h>
LPSTR StrGlobalError = NULL;//This is what I'm trying to avoid.
VOID SetErrorString ( LPSTR StrError )
{
StrGlobalError = StrError;
}
LPSTR StrGetErrorString()//Using a global variable like this makes this function useless
{
return StrGlobalError;
}
Thanks, Ktulu.