Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Pause for storage relocation.


devel / comp.lang.misc / Re: C++ scope-resolution double-colon operator :: and dot .

SubjectAuthor
* C++ scope-resolution double-colon operator :: and dot .James Harris
`* Re: C++ scope-resolution double-colon operator :: and dot .Bart
 `- Re: C++ scope-resolution double-colon operator :: and dot .David Brown

1
C++ scope-resolution double-colon operator :: and dot .

<sftdou$guq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=450&group=comp.lang.misc#450

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: C++ scope-resolution double-colon operator :: and dot .
Date: Sun, 22 Aug 2021 12:51:57 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <sftdou$guq$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 22 Aug 2021 11:51:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4320f136d049292b87700e2ad4187466";
logging-data="17370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gTt80g8Ygcte7EPxULhs9YOcAoidPXDM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:2zRNr3KNHuM8Lb0rDa3JIgOJOhc=
Content-Language: en-GB
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: James Harris - Sun, 22 Aug 2021 11:51 UTC

Following other discussions here I find myself having to read C++ code
and, frankly, I know very little about it so I have a basic question:

What does the :: operator mean and could be replaced - in a better
language - with a dot?

As I have it,

A.B

refers to B as a name within A. That form is perhaps most familiar as
identifying a field in a record but I currently have it as picking any
name from any namespace. So what would C++'s double colon add to that?

--
James Harris

Re: C++ scope-resolution double-colon operator :: and dot .

<sftjia$our$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=451&group=comp.lang.misc#451

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: C++ scope-resolution double-colon operator :: and dot .
Date: Sun, 22 Aug 2021 14:30:49 +0100
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <sftjia$our$1@dont-email.me>
References: <sftdou$guq$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 22 Aug 2021 13:30:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="89aba07fb8834fa5f9ebe6b351ab14d8";
logging-data="25563"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wprJq1/wyQADAY4Lxr9oTTa1Au1Rw6NM="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:N2XsMf9XrbMwPOOunDdogp8vQ28=
In-Reply-To: <sftdou$guq$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210822-0, 22/8/2021), Outbound message
 by: Bart - Sun, 22 Aug 2021 13:30 UTC

On 22/08/2021 12:51, James Harris wrote:
> Following other discussions here I find myself having to read C++ code
> and, frankly, I know very little about it so I have a basic question:
>
> What does the :: operator mean and could be replaced - in a better
> language - with a dot?

Short answer: yes.

> As I have it,
>
>   A.B
>
> refers to B as a name within A. That form is perhaps most familiar as
> identifying a field in a record but I currently have it as picking any
> name from any namespace. So what would C++'s double colon add to that?

Nothing, except telling you that A::B is doing scope resolution rather
member selection. With A.B, either thing could be going on.

But I've also seen :: used by itself as in ::B. Not sure what that
means, I guess some default (std?) is assumed to go before the ::.

Re: C++ scope-resolution double-colon operator :: and dot .

<sftlpl$7vo$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=454&group=comp.lang.misc#454

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.misc
Subject: Re: C++ scope-resolution double-colon operator :: and dot .
Date: Sun, 22 Aug 2021 16:08:53 +0200
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <sftlpl$7vo$1@dont-email.me>
References: <sftdou$guq$1@dont-email.me> <sftjia$our$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 22 Aug 2021 14:08:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="efb733fa4a65d95ba93d60fb56dad6c3";
logging-data="8184"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fl4P/dWtNj9pp4cKu/i4ByzElYT53+CY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:MqZj4I6nqDkY0sSxsMVyJIt+g5o=
In-Reply-To: <sftjia$our$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 22 Aug 2021 14:08 UTC

On 22/08/2021 15:30, Bart wrote:
> On 22/08/2021 12:51, James Harris wrote:
>> Following other discussions here I find myself having to read C++ code
>> and, frankly, I know very little about it so I have a basic question:
>>
>> What does the :: operator mean and could be replaced - in a better
>> language - with a dot?
>
> Short answer: yes.
>

Agreed, for the short answer.

Longer answer: it could be replaced by a dot, but that would not
necessarily be better. There are clarity advantages to have more than
one scoping operator to distinguish between different uses.

>> As I have it,
>>
>>    A.B
>>
>> refers to B as a name within A. That form is perhaps most familiar as
>> identifying a field in a record but I currently have it as picking any
>> name from any namespace. So what would C++'s double colon add to that?
>
>
> Nothing, except telling you that A::B is doing scope resolution rather
> member selection. With A.B, either thing could be going on.

Exactly.

>
> But I've also seen :: used by itself as in ::B. Not sure what that
> means, I guess some default (std?) is assumed to go before the ::.
>

If you write something like :

namespace A {
int x;
}

namespace B {
namespace A {
int y;
}
}

using namespace B;

int z = A::x;

then the compiler will complain about the ambiguity - it can see two
completely different namespaces called "A" (the global one, and the one
pulled into the global space by "using namespace B;"). But you can write:

int z = ::A::x;

to skip the "using namespace" shortcuts and go back up to the root of
the namespaces.

There are a few people who insist on writing "::std::" instead of
"std::" in C++, through some misguided belief that it makes their code
safer or more robust in the face of some C++ programmer defining their
own "std" namespace. Most C++ programmers consider it totally
unnecessary and a bad habit.

But there can be other occasions with complicated namespace setups where
a global scope namespace initial "::" is helpful.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor