如果您转到此 post 的已接受答案
有人可以详细说明他为什么使用:
double temp = ::atof(num.c_str());
而不仅仅是
double temp = atof(num.c_str());
另外,当您使用“纯”全局函数时,使用该语法是否被认为是一种好习惯?
最佳答案
它说使用全局版本,而不是在本地范围内声明的版本。所以如果有人在你的类中声明了一个 atof
,这肯定会使用全局的。
#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/