gpt4 book ai didi

c++ - "::"在 C++ 中是什么意思?

转载 作者:IT老高 更新时间:2023-10-28 22:23:49 32 4
gpt4 key购买 nike

这个符号是什么意思?

AirlineTicket::AirlineTicket()

最佳答案

::是 scope resolution operator - 用于限定名称。在这种情况下,它用于将类 AirlineTicket 与构造函数 AirlineTicket() 分开,形成限定名称 AirlineTicket::AirlineTicket()

当您需要明确说明您所指的内容时,您可以使用它。一些样本:

namespace foo {
class bar;
}
class bar;
using namespace foo;

现在您已经使用范围解析运算符来引用特定的条了。

::foo::bar 是完全限定名称。

::bar 是另一个完全限定名称。 (:: 首先表示“全局命名空间”)

struct Base {
void foo();
};
struct Derived : Base {
void foo();
void bar() {
Derived::foo();
Base::foo();
}
};

这使用范围解析来选择特定版本的 foo。

关于c++ - "::"在 C++ 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5345527/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com