typedef a function pointer

the c++ primer books says the syntax is like this:

typedef bool (*cmpFcn) (const string &, const string &);

so that cmpFcn is a name of type that is a pointer to function.

while what I expect is like this:

typedef bool (*) (const string &, const string &) cmpFcn;

because this looks more similar with

typedef long index_t;

do you guys ever feel c++ syntax is complicated, not consistently complying with some general rule?
> while what I expect is like this:
> typedef bool (*) (const string &, const string &) cmpFcn;

That is not allowed; typedef has C syntax rules (warts and all).

This is allowed:
using cmpFcn = bool(*)( const std::string&, const std::string& ) ; // no C baggage to carry


These also provide more readable syntax:
1
2
3
4
5
6
using cmp_fn_type = bool( const std::string&, const std::string& ) ;
using cmpFcn = cmp_fn_type* ;

// or with typedef:
typedef bool cmp_fn_type( const std::string&, const std::string& ) ;
typedef cmp_fn_type* cmpFcn ;
Thanks, JLBorges, that is very clear explanation!
Topic archived. No new replies allowed.