Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Error message when defining a static data member

38 views
Skip to first unread message

Ian Collins

unread,
May 10, 2017, 4:41:55 AM5/10/17
to
On 05/10/17 08:32 PM, Stefan Ram wrote:
> I have this line of code:
>
> using u = ::my_class; ::std::vector< ::my_class::listentry >u::list;
>
> , and it compiles just fine. However,
> if I change it to
>
> ::std::vector< ::my_class::listentry >::my_class::list;
>
> , I get this error from GCC (IIRC 5.1):
>
> main.cpp: At global scope:
> main.cpp:40:41: error: 'my_class' in 'class std::vector<my_class::listentry>' does not name a type
> ::std::vector< ::my_class::listentry >::my_class::list;
> ^

All those spurious colons make it hard to read and it looks like they
have confused you as well.. Shouldn't that be

std::vector<my_class::listentry> my_class::list;

--
Ian

Alf P. Steinbach

unread,
May 10, 2017, 4:44:24 AM5/10/17
to
On 10-May-17 10:32 AM, Stefan Ram wrote:
> I have this line of code:
>
> using u = ::my_class; ::std::vector< ::my_class::listentry >u::list;
>
> , and it compiles just fine. However,
> if I change it to
>
> ::std::vector< ::my_class::listentry >::my_class::list;
>
> , I get this error from GCC (IIRC 5.1):
>
> main.cpp: At global scope:
> main.cpp:40:41: error: 'my_class' in 'class std::vector<my_class::listentry>' does not name a type
> ::std::vector< ::my_class::listentry >::my_class::list;
> ^

`::` does double duty both as scope resolution operator and as name of
the global scope.

You intend the latter but you get the former.

Just omit that `::`. ;-)


Cheers & hth.,

- Alf

Ian Collins

unread,
May 10, 2017, 6:30:27 AM5/10/17
to
On 05/10/17 09:01 PM, Stefan Ram wrote:
> Now I see. Thank you!
>
> It seems that I also can use braces:
>
> ::std::vector< ::my_class::listentry >( ::my_class::list );

It's much easier and clearer to omit the superfluous colons.

--
Ian

Scott Lurndal

unread,
May 10, 2017, 8:47:34 AM5/10/17
to
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Distribution through any means other than regular usenet
>
> channels is forbidden. It is forbidden to publish this
>
> article in the world wide web. It is forbidden to change
>
> URIs of this article into links. It is forbidden to remove
>
> this notice or to transfer the body without this notice.
>X-No-Archive: Yes
>Archive: no
>X-No-Archive-Readme: "X-No-Archive" is only set, because this prevents some
>
> services to mirror the article via the web (HTTP). But Stefan Ram
>
> hereby allows to keep this article within a Usenet archive server
>
> with only NNTP access without any time limitation.
>X-No-Html: yes
>Content-Language: en
>X-Received-Body-CRC: 1152000637
>X-Received-Bytes: 2071
>

>
> It seems that I also can use braces:
>
>::std::vector< ::my_class::listentry >( ::my_class::list );
>

Or do as has been suggested and lose the leading "::". I really
hope you don't teach your students that practice, as it will cause
them problems once they hit the real world.

woodb...@gmail.com

unread,
May 10, 2017, 12:55:14 PM5/10/17
to
On Wednesday, May 10, 2017 at 7:47:34 AM UTC-5, Scott Lurndal wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
> > Distribution through any means other than regular usenet
> >
> > channels is forbidden. It is forbidden to publish this
> >
> > article in the world wide web. It is forbidden to change
> >
> > URIs of this article into links. It is forbidden to remove
> >
> > this notice or to transfer the body without this notice.
> >X-No-Archive: Yes
> >Archive: no
> >X-No-Archive-Readme: "X-No-Archive" is only set, because this prevents some
> >
> > services to mirror the article via the web (HTTP). But Stefan Ram
> >
> > hereby allows to keep this article within a Usenet archive server
> >
> > with only NNTP access without any time limitation.
> >X-No-Html: yes
> >Content-Language: en
> >X-Received-Body-CRC: 1152000637
> >X-Received-Bytes: 2071
> >
>
> >
> > It seems that I also can use braces:
> >
> >::std::vector< ::my_class::listentry >( ::my_class::list );
> >

Interesting.

>
> Or do as has been suggested and lose the leading "::". I really
> hope you don't teach your students that practice, as it will cause
> them problems once they hit the real world.

I use a similar form as Stefan and am happy with it.


Brian
Ebenezer Enterprises - Enjoy programming again.
http://webEbenezer.net

Scott Lurndal

unread,
May 10, 2017, 1:30:20 PM5/10/17
to
You are atypical.

woodb...@gmail.com

unread,
May 10, 2017, 2:33:43 PM5/10/17
to
Not really. Others love G-d and country and baseball.

David Brown

unread,
May 11, 2017, 2:46:42 AM5/11/17
to
This is a C++ newsgroup, and the discussion was on the C++ style of
using a leading "::". In that, you are atypical. Nobody cares about
your hobbies or whether they are popular or not.

I don't believe I have seen the preceding :: style anywhere except from
you and Stefan. Maybe there are a few more people that use it, but you
will be heavily outweighed by people using "using" to minimise the need
for ::, rather than people who add it superfluously. It is definitely
atypical.

Dombo

unread,
May 20, 2017, 3:24:03 PM5/20/17
to
Op 11-May-17 om 8:46 schreef David Brown:

> I don't believe I have seen the preceding :: style anywhere except from
> you and Stefan. Maybe there are a few more people that use it, but you
> will be heavily outweighed by people using "using" to minimise the need
> for ::, rather than people who add it superfluously. It is definitely
> atypical.

As a contractor I've worked for many organizations, and I have never
seen the leading "::" used or recommended as a coding style. The use of
superfluous colons would be frowned upon at the very least, and more
likely would would lead to a reject when the code is reviewed. The C++
syntax is already noisy enough as it is; there is no point in making the
code even harder to read. The question of the TS illustrates why the
superfluous colons are a bad idea.

It surprises me that some of the people here seem to go out of their way
to write obfuscated code and then ask for help.


0 new messages