This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: pointer member constant expression
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Perry Smith" <pedz at easesoftware dot net>
- Cc: "GCC Mailing List" <gcc at gcc dot gnu dot org>
- Date: Fri, 24 Feb 2006 15:55:21 +0100
- Subject: Re: pointer member constant expression
- References: <2E1CFEA4-135B-47E8-A4FB-5360775BC2B1@easesoftware.net>
On 2/24/06, Perry Smith <pedz@easesoftware.net> wrote:
> I have asked this question before -- maybe to the gcc-help list but
> I'm still unclear.
>
> The problem is this:
>
> struct foo {
> int a;
> int b;
> int c;
> };
>
> static const int foo::*j = &foo::c; // accepted
>
> class dog {
> static const int foo::*k = &foo::c; // error
> };
>
> 5.19 (constant expressions) paragraph 2, the last item in the 1998 C+
> + spec says " -- a pointer to member constant expression." That
> appears to be defined as: '&' qualified-id (5.19 paragraph 6).
>
> So is the line in error legal C++ or not?
No.
t.C:10: error: 'foo::c' cannot appear in a constant-expression
t.C:10: error: `&' cannot appear in a constant-expression
t.C:10: error: invalid in-class initialization of static data member
of non-integral type 'const int foo::*'
use
class dog {
static const int foo::*k;
};
const int foo::*dog::k = &foo::c;
Richard.
> Thanks,
> Perry
>
>