Home > Backend Development > C#.Net Tutorial > What do two colons mean in C language?

What do two colons mean in C language?

下次还敢
Release: 2024-05-07 07:42:17
Original
1226 people have browsed it

The meaning of two colons (::) in C language: Scope resolution operator: resolves names in the scope, allowing access to names outside the current scope. Nested type name: Specify the name of the nested type, used to refer to the nested type.

What do two colons mean in C language?

The meaning of two colons in C language

In C language, the double colon (::) has the following meaning Two meanings:

1. Scope resolution operator

Double colon is used to resolve names in the scope. It allows access to names outside the current scope. For example:

<code class="c">int main() {
  int x = 10;
  {
    int x = 20;
    cout << ::x; // 输出 10
  }
  return 0;
}</code>
Copy after login

In the inner scope, the x variable declared in the outer scope is accessed through ::x.

2. Nested type name

Double colon is used to specify the name of the nested type. For example:

<code class="c">namespace myNamespace {
  class MyClass {
    struct InnerClass {
      // ...
    };
  };
}</code>
Copy after login

To refer to a nested type, use a double colon:

<code class="c">myNamespace::MyClass::InnerClass innerObject;</code>
Copy after login

The above is the detailed content of What do two colons mean in C language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template