typedef


Dear all,
I am looking through a c++ code and I have found a typedef statement that I do not understand. it is on line 6 of the code below. Does anybody knows what that means? I always thought that typedef allows you to give a different name to a variable type, but here something else seems to be going on.
thanks in advance.

1
2
3
4
5
6
7
8
9
template<typename BaseClassType, typename UniqueIdType>
class ObjectFactory<BaseClassType (), UniqueIdType>
{
protected:

    typedef BaseClassType (*CreateObjectFunc)();

     (...)
}
closed account (zb0S216C)
The type-definition you see can be described as: "Let "CreateObjectFunc" be an alias for a pointer to a non-member function, that returns a "BaseClassType", and accepts no arguments.

Wazzak
Last edited on
Another way to do the same is to define typedef for the corresponding function.

typedef BaseClassType TFunc();

It looks like a function declaration except that it follows keyword typedef.
Here TFunc is not a real function declaration. Here TFunc names any function that has return type BaseClassType and has no parameters.
Later you can declare a pointer to such a function as for example

TFunc *fp = SomeRealFunctionName;
Last edited on
thanks!
Topic archived. No new replies allowed.