The chasm between knowing how to do something and knowing why it's done a particular way is the difference between being a coder and a designer. With that in mind, I came upon a situation a short time back that I can certainly code, but I must confess that the subtlety of "why" has escaped me. Here's the story -- let's see if anyone can explain the detail that I'm missing. (please?) :)
I've got my hands into an old application and trying to marry "the old and the new". The code contains a table (of structures) with two key elements -- a C string and a class pointer.
The key elements of the structures are in the snippets below.
My question regards the dereferencing of the Handler pointer in the TReport object in the KeyStrings table.
Intuitively, I want to do something like this:
But C++ gives the error: Undefined Symbol 'Handler'. (BTW, 'Handler' is declared *public*.)
I can certainly call the function if the statement is recoded into discrete steps.
void __fastcall (TReport::*Handler) (char *);
Report = KeyStrings[MessageType].Re
Handler = KeyStrings[MessageType].Re
So what did I miss?
// The TReport class contains the function processors for all of the handled strings.
typedef void __fastcall (TReport::*handler_t) (char *);
void __fastcall ReportxxHandler (char *String);
void __fastcall Report00Handler (char *String);
void __fastcall Report20Handler (char *String);
// The processor_t structure links a string with the report object that will process it.
// Define the handled strings and processors.
processor_t KeyStrings =
"String1", 0, // The TReport object is created at run time.