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

What do two colons mean in C language?

下次还敢
下次还敢Original
2024-05-07 07:42:171259browse

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>

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>

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

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

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!

Statement:
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