Name look up rules

P

puzzlecracker

example is taken from Evolution of C++.

I don't understand how the following will be interpreted:

typedef int P();
typedef int Q();

class X{
static P(Q);
static Q(P);
};


Thanks
 
V

Victor Bazarov

puzzlecracker said:
example is taken from Evolution of C++.

I don't understand how the following will be interpreted:

typedef int P();
typedef int Q();


Seems like ::p is a synonym for the type "a function that takes
no arguments and returns an int".

::Q is the same type synonym as ::p.
class X{
static P(Q);
static Q(P);

These two lines are syntax errors. Implicit return type is not
allowed (there is nothing between 'static' and the names).

V
 
B

Bo Persson

Victor Bazarov said:
Seems like ::p is a synonym for the type "a function that takes
no arguments and returns an int".

::Q is the same type synonym as ::p.


These two lines are syntax errors. Implicit return type is not
allowed (there is nothing between 'static' and the names).

Only the second line is in error. On the first line, P is the type
from the typedef, so it declares Q as a static something (a function I
guess:).

On the second line, the new X::Q hides the type Q so it doesn't work
here.


Writing the lines as

static P Q;
static Q P;

would have made it too obvious.


Bo Persson
 

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

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top