static const integral members
  Home FAQ Contact Sign in
comp.lang.c++.moderated only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c++.moderated Profile…
 Up
static const integral members         


Author: Roman.Perepelitsa
Date: Apr 11, 2008 09:41

I have a question regarding the following snippet of code.

struct foo
{
static const int value = 1;
};

int main()
{
int bar = foo::value;
}

Is it valid C++?

First of all, I'm sure that the following is valid:
// foo is the same
int main()
{
int bar[foo::value];
}
Show full article (1.81Kb)
6 Comments
Re: static const integral members         


Author: Daniel Krügler
Date: Apr 11, 2008 16:20

On 11 Apr., 19:34, "Roman.Perepeli...@gmail.com"
gmail.com> wrote:
> I have a question regarding the following snippet of code.
>
> struct foo
> {
> static const int value = 1;
> };
>
> int main()
> {
> int bar = foo::value;
> }
>
> Is it valid C++?

According to the wording of ISO 14882/2nd edition
this program violates the one definition rule,
because foo::value is not defined, but used, as
shown by the quotes you provided.
Show full article (2.84Kb)
no comments
Re: static const integral members         


Author: Carl Barron
Date: Apr 12, 2008 10:10

In article
x41g2000hsb.googlegroups.com>,
Daniel Krügler googlemail.com> wrote:
Show full article (1.19Kb)
no comments
Re: static const integral members         


Author: Alberto Ganesh Barbati
Date: Apr 12, 2008 22:50

Carl Barron ha scritto:
> In article
> x41g2000hsb.googlegroups.com>,
> Daniel Kr
no comments
Re: static const integral members         


Author: Daniel Krügler
Date: Apr 12, 2008 22:51

On 12 Apr., 20:06, Carl Barron adelphia.net> wrote:
> In article
> x41g2000hsb.googlegroups.com>,
>
>
>
> Daniel Krügler googlemail.com> wrote:
>> On 11 Apr., 19:34, "Roman.Perepeli...@gmail.com"
>> gmail.com> wrote:
>>> I have a question regarding the following snippet of code.
>
>>> struct foo
>>> {
>>> static const int value = 1;
>>> };
>
>>> int main()
>>> {
>>> int bar = foo::value;
>>> } ...
Show full article (2.84Kb)
no comments
Re: static const integral members         


Author: Carl Barron
Date: Apr 13, 2008 10:51

In article
<1d29a464-41dc-4986-97f6-549943e2f015@b64g2000hsa.googlegroups.com>,
Daniel Krügler googlemail.com> wrote:
> On 12 Apr., 20:06, Carl Barron adelphia.net> wrote:
>> In article
>> x41g2000hsb.googlegroups.com>,
>>
>>
>>
>> Daniel Krügler
Show full article (3.42Kb)
no comments
Re: static const integral members         


Author: Daniel Krügler
Date: Apr 13, 2008 16:30

On 13 Apr., 20:45, Carl Barron adelphia.net> wrote:
> The point is
> struct foo
> {
> static const int value = 1;
> };
>
> does not automatically violate ODR only different defintions of foo
> would do so. The sniplet does not involve multiple defintions of foo
> or
> foo::value. and the sniplet is legal and valid.

This is an incorrect/misleading statement as written. The
ODR is does not only rule *multiple* definitions, it does
also rule *missing* definitions. You can interpret that as
a *one-and-only-one-definition*. [basic.def.odr]/3 says
precisely this:
Show full article (2.38Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
US-NY: New York-Business Integration & Optimization - Integration Senior...nyc.jobs.offered ·
Re: Global Const vs Public Constmicrosoft.public.vb.general.discussion ·
[PATCH -mm] consolidate asm/const.h to linux/const.hlinux.kernel ·