C ++:::的作用是什么? [英] C++ : what is :: for?

查看:95
本文介绍了C ++:::的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您转到此帖子

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

Could someone please elaborate on why he uses:

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

而不是简单地

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

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

Also, is it considered a good practice to use that syntax when you use "pure" global functions?

推荐答案

它说使用全局版本,而不是在本地范围内声明的版本.因此,如果有人在您的课程中声明了 atof ,那么一定要使用全局代码.

It says use the global version, not one declared in local scope. So if someone's declared an atof in your class, this'll be sure to use the global one.

看看有关此主题的维基百科:

#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 ++:::的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆