DanielEKFA wrote:[color=blue]
>
> Hmm... Not sure how to crack this one. I have this code:
>
> typedef bool execFunctionType(const commandDataType&);
>
> struct commandDataType
> {
> SymbolSequence Sequence;
> string command;
> execFunctionType* executer;
> };
>
> As you can see, the execFunctionType takes as an argument a
> commandDataType struct which contains a pointer to a function of type
> execFunctionType. Logically this is okay (at least according to my
> logic ;), yet the thing won't compile because the struct needs the
> typedef to be defined before it to make sense of the execFunctionType,
> and the typedef needs the struct to be defined before it to make sense
> of the struct...[/color]
And here is your thinking flawed.
The typedef doesn't need the struct to be completely declared. All the
compiler needs to know is that somewhere there is a 'struct commandDataType'.
But it doesn't need to know all the details of that struct.
Thus a forward declaration is sufficient:
struct commandDataType;
typedef bool execFunctionType(const commandDataType&);
struct commandDataType
{
SymbolSequence Sequence;
string command;
execFunctionType* executer;
};
Note that in C++ you rarely need function pointers. So it might be
that you are baring up the wrong tree and what you really want is
a class hierarchy with virtual functions.
--
Karl Heinz Buchegger
kbuchegg@gascad.at