为什么代码"foo :: foo :: foo :: foob"编译?

编程入门 行业动态 更新时间:2024-10-27 13:34:37
本文介绍了为什么代码"foo :: foo :: foo :: foob"编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一个同事不小心写了这样的代码:

A co-worker accidentally wrote code like this:

struct foo { foo() : baz(foobar) {} enum bar {foobar, fbar, foob}; bar baz; }; void f() { for( auto x : { foo::foobar, foo::fbar, foo:: foo:: foo::foob } ); // ... }

GCC 5.1.0对此进行了编译.

GCC 5.1.0 compiles this.

进行此编译的规则是什么?

What's the rule that makes this compile?

推荐答案

注入了-此处使用类名,

出于查找(除非用于命名构造函数):这称为注入类名称

the name of the class within its own definition acts as a public member type alias of itself for the purpose of lookup (except when used to name a constructor): this is known as injected-class-name

然后

foo:: foo:: foo::foob

即foo::foo::foo::foob与foo::foob相同.

然后for (auto x : {foo::foobar, foo::fbar, foo::foob })是基于范围的for循环(因为C ++ 11),它会在 braised-init-list 由3个枚举数组成.

And then for (auto x : {foo::foobar, foo::fbar, foo::foob }) is a range-based for loop (since C++11), which iterates on the braced-init-list formed by the 3 enumerators.

更多推荐

为什么代码"foo :: foo :: foo :: foob"编译?

本文发布于:2023-10-16 15:52:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498029.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   quot   foob   foo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!