I
Ian Collins
This one had me going today.
I have a class that distils down to
template <typename T>
struct X
{
mutable T t;
};
where T is the type of a function parameter extracted by a script. For
one function I kept getting bizarre compiler errors like these:
Member functions may not be declared with template type parameters.
A function cannot be declared to be mutable.
The hint came from g++:
field 'X<void ()()>::t' invalidly declared function type
It turned out one of the function's parameters was a callback typedef'd as:
typedef void (fn)()
Note the absent '*'. In the code it can be used interchangeably with
fn*, but when used as a template argument, fun ensues.
No wonder people call C's function pointer syntax crazy.
I have a class that distils down to
template <typename T>
struct X
{
mutable T t;
};
where T is the type of a function parameter extracted by a script. For
one function I kept getting bizarre compiler errors like these:
Member functions may not be declared with template type parameters.
A function cannot be declared to be mutable.
The hint came from g++:
field 'X<void ()()>::t' invalidly declared function type
It turned out one of the function's parameters was a callback typedef'd as:
typedef void (fn)()
Note the absent '*'. In the code it can be used interchangeably with
fn*, but when used as a template argument, fun ensues.
No wonder people call C's function pointer syntax crazy.