在c++中,双冒号前的&符号是什么意思?
what does a ampersand before double colon mean in c++?
我在以下由google的protobuf生成的代码中发现了这种用法。
inline void Datum::set_data(const void* value, size_t size) {
set_has_data();
//over here.
if (data_ == &::google::protobuf::internal::kEmptyString) {
data_ = new ::std::string;
}
data_->assign(reinterpret_cast<const char*>(value), size);
}
谢谢:-)!
这是两件完全不相关的事情,也许最好把它们看作
&(::google::protobuf::internal::kEmptyString)
&
只是表示地址运算符,就像你做的那样:
int xyzzy = 7;
int *pointer_to_xyzzy = &xyzzy;
另一方面,::
是全局命名空间说明符,以确保您不会开始查找当前命名空间。
例如,以下程序:
#include <iostream>
int x = 7;
namespace xyzzy {
int x = 42;
int getxa() { return ::x; }
int getxb() { return x; }
}
int main() {
std::cout << xyzzy::getxa() << 'n';
std::cout << xyzzy::getxb() << 'n';
return 0;
}
输出7
后接42
,因为getxa()
函数使用全局命名空间说明符而不是xyzzy
。
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 符号":" C 和 C++ 中是什么意思?
- 这种错误的原因是什么:将"功能"重新定义为不同类型的符号
- 在C++中,将无符号整数转换为八进制表示,反之亦然的最佳方法是什么
- 这个星号 (*) 符号在 C++ 中是什么意思?-- 指向成员的指针
- 在这段 python 代码中,大于符号是什么意思
- 该代码中的符号是什么意思?[]()
- 成员函数签名末尾的 &(& 符号)是什么意思?
- 符号<>是什么意思?
- 下面的符号是什么意思
- 错误LNK2019中的 @ 符号是什么意思
- 导出符号是什么意思
- "错误LNK2019:未解析的外部符号"是什么意思?
- 解析一个符号是什么意思
- nm 命令输出中的"@@"符号是什么意思?
- 在c++中,双冒号前的&符号是什么意思?
- C++中数据类型后面的符号'^'是什么意思?
- 符号名后面的@@符号是什么意思?
- VB DLL 中的下划线符号是什么