为什么std:set(使用单个冒号)可以编译? [英] Why can std:set (with a single colon) compile?

查看:81
本文介绍了为什么std:set(使用单个冒号)可以编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心写了

std::set<string> keys;

为:

std:set<string> keys;

但奇怪的是,Visual Studio 2013仍在编译.

but weirdly enough, Visual Studio 2013 still compiles.

为什么会这样?

实际上,不仅被定义,而且后来被用作一组字符串,例如

Actually keys is not only defined, but later used as a set of strings, such as

if(keys.find(keystr)==keys.end()){
    keys.insert(keystr);
    toret.push_back(tempv);
}

推荐答案

在块范围内,标识符后跟单个冒号会引入一个标签.因此,您的声明等同于:

At block scope, an identifier followed by a single colon introduces a label. Thus, your statement is equivalent to:

set<string> keys;

除了带有标签 std 并且可以被语句 goto std; 跳转到.

except that it bears the label std and can be jumped to by the statement goto std;.

由于某种原因,名称 set 为编译器所知-也许您使用名称空间std; 或 std :: set;进行了设置.之类的东西,或者您可能在某处定义了自己的 set 类型.

For some reason, the name set is known to the compiler---perhaps you did using namespace std;, or using std::set;, or something like that, or perhaps you defined your own set type somewhere.

这篇关于为什么std:set(使用单个冒号)可以编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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