C++:什么是::for?

标签 c++

如果您转到此 post 的已接受答案

有人可以详细说明他为什么使用:

double temp = ::atof(num.c_str());

而不仅仅是

double temp = atof(num.c_str());

另外,当您使用“纯”全局函数时,使用该语法是否被认为是一种好习惯?

最佳答案

它说使用全局版本,而不是在本地范围内声明的版本。所以如果有人在你的类中声明了一个 atof,这肯定会使用全局的。

看看Wikipedia on this subject :

#include <iostream>

using namespace std;

int n = 12;   // A global variable

int main() {
    int n = 13;   // A local variable
    cout  << ::n << endl;  // Print the global variable: 12
    cout  << n   << endl;  // Print the local variable: 13
}

关于C++:什么是::for?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2282725/

相关文章:

c++ - _beginthread 疑似内存泄漏

c++ - 从另一个函数控制 RenderWindow

c++ - LLVM CreateFCmpONE 等效于整数

c++ - 编译时如何选择方法?

c++ - 疯狂计算器

c++ - 使用静态链接编译 hdf5 项目

c++ - 试图写一个二进制文件,得到一个文本文件

c++ - 从 std::vector 获取最后一个元素

c++ - 如何在 C++ 中读取 MNIST 数据?

c++ - 仅包含<opencv2/opencv.hpp>会导致链接错误