简单的问题是,这个有效的C ++:
class Foo { void Foo::doSomething(); };问题的关键在于:在类声明中有效的方法名称之前是否重复使用了类名和双冒号?
我遇到了编译代码的问题,它使用g ++ 4.2.3来做到这一点。 在挖掘和更改代码之前,我希望看到对描述此语法的内容的引用。 或降级编译器; 这确实使用g ++ 3.3.6构建。
我得到的错误是(大致):
Foo.h:3: error: extra qualification ‘Foo::’ on member ‘doSomething’我做了谷歌,但不能拿出一些东西。 我没有这个标准,即使我这样做了,也许会花费我很长一段时间才能找到具有权威性的东西。 我不是C ++语言的律师。
Simple question, is this valid C++:
class Foo { void Foo::doSomething(); };The point of the question: is that repeated use of the class name and double colon before the method name valid inside the class declaration?
I'm having issues compiling code that does this using g++ 4.2.3. I would love to see a reference to something describing the syntax here, before digging in and changing the code. Or downgrading the compiler; this does build with g++ 3.3.6.
The error I'm getting is (roughly):
Foo.h:3: error: extra qualification ‘Foo::’ on member ‘doSomething’I did Google, but couldn't come up with something. I don't have the standard, and even if I did it would probably take me quite a while to find anything authoritative. I'm no C++ language lawyer.
最满意答案
我看了一下标准,第9.2节将是相关部分。 我对BNF并不是很了不起,但是我没有看到BNF上的任何类别成员都会表示这是允许的。 该标识符在BNF中甚至被命名为“非限定标识”。
G ++在4.1版中改变了行为,显然很多其他编译器都接受了这一点,但我从未见过这种风格,我不知道为什么有人会这样做。 由于它似乎不会在各种各样的编译器上触发错误,所以这种风格可能有一些历史原因,但据我所知它确实是无效的。
我通过Google发现的唯一的好参考就是这个页面 ,它只是试图解释一些G ++ 4.1的变化。
I took a look at the standard, section 9.2 would be the relevant portion. I'm not that great with BNF but I didn't see anything in the BNF for class members that would indicate this was allowed. The identifier is even named "unqualified-id" in the BNF.
G++ changed the behavior in version 4.1, and apparently a lot of other compilers accepted this, but I've never seen this style used and I have no idea why anyone would do it. Since it seems to not trigger an error on a pretty wide variety of compilers, there may be some historical reason for this style, but as far as I can tell it's indeed not valid.
The only good reference I found through Google was this page, which just attempts to explain some of the changes in G++ 4.1.
更多推荐
发布评论