c++/1841: Incorrect error: invalid use of member '' in staticmember function
'Neil Booth'
neil@daikokuya.demon.co.uk
Sat Feb 3 02:00:00 GMT 2001
Martin Sebor wrote:-
> > > > struct X
> > > > {
> > > > static int X::* foo () { return &x; };
> > > >
> > > > int x;
> > > > };
> The code is incorrect, the type of the result is int*, the type
> returned from the function is int X::*. Here's the relevant text:
>
> 5.3.1, p2: "The result of the unary & operator is a pointer to its
> operand. The operand shall be an lvalue or a qualified-id. In the
> first case, if the type of the expression is ``T,'' the type of the
> result is ``pointer to T.'' In particular, the address of an object
> of type ``cv T'' is ``pointer to cv T,'' with the same
> cv-qualifiers. For a qualified-id, if the member is a static member
> of type ``T'', the type of the result is plain ``pointer to T.'' If
> the member is a nonstatic member of class C of type T, the type of
> the result is ``pointer to member of class C of type T.'
Hi Martin,
You've confused me now. According to the last few words of what you
quoted, I read that the type of "&x" is int X::*. That is the type
being returned in the function prototype. So what's wrong?
Neil.
More information about the Gcc-bugs
mailing list