范围分辨率运算符 [英] Scope resolution operator

查看:138
本文介绍了范围分辨率运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现这是在我正在看的源代码之一。

I accidentally happened to find this in one of the source codes I was looking at. So, I'm giving a similar smaller example here.

test.h b $ b

#include<iostream>

class test{
    int i;
public:
    test(){}
    //More functions here
};

在文件 test.cpp 中:

#include "test.h"

int main()
{
    test test1;
    test::test test2;
    test::test::test test3;
    return 0;
}

首先,是否有理由声明 test2 那样吗?其次,这个代码在g ++版本4.4.3和更低版本中编译得很好。在C ++标准中有一些东西,说,当不需要解析范围时,范围解析操作符被忽略。

First of all, is there a reason to declare test2 that way? Secondly, this code compiles just fine in g++ version 4.4.3 and lower versions. Is there something in the C++ standard, saying, scope resolution operators are ignored when there is no need to resolve scope?

推荐答案

代码无效。

这是g ++中的一个错误,它接受了代码。请参见g ++不正确处理注入的类名称。错误是解决为在2009年固定,因此它应该固定在任何最新版本的g ++。

It was a bug in g++ that it accepted the code. See "g++ does not treat injected class name correctly." The bug was resolved as fixed in 2009, so it should be fixed in any recent version of g++.

这篇关于范围分辨率运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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