C++ declarative syntax

M

muler

Q: Write a function declaration that takes a double argument and
returns a pointer to a function that takes an int argument and
returns
a pointer to char without using a typedef?

using a typedef, it's easy:

typedef char* (*Ptr_func)(int);
Ptr_func Func(double);

Thanks,
 
S

SG

Q: Write a function declaration that takes a double argument and
returns a pointer to a function that takes an int argument and
returns
a pointer to char without using a typedef?

using a typedef, it's easy:

typedef char* (*Ptr_func)(int);
Ptr_func Func(double);

char *(*Func(double))(int);

Not that I would write something like this without a typedef in real
code. Basically, you have a type on the left side -- here: char -- and
a declarator on the right side -- here: *(*Func(double))(int). You
can think of the declarator like an expression and the type infront of
the declarator spedifies the type of this expression. The only
difference between declarator and expression that comes to my mind
right now is that the unary ampersand has a different meaning. The
unary ampersand is an address operator in an expression and a
"reference declarator" in a declarator. With this understanding, you
can read the above declaration "inside out".

SG
 
M

muler

  char *(*Func(double))(int);

Not that I would write something like this without a typedef in real
code. Basically, you have a type on the left side -- here: char -- and
a declarator on the right side  -- here: *(*Func(double))(int). You
can think of the declarator like an expression and the type infront of
the declarator spedifies the type of this expression. The only
difference between declarator and expression that comes to my mind
right now is that the unary ampersand has a different meaning. The
unary ampersand is an address operator in an expression and a
"reference declarator" in a declarator. With this understanding, you
can read the above declaration "inside out".

SG

nice!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top