点运算符和范围解析运算符之间的区别 [英] whats the difference between dot operator and scope resolution operator

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

问题描述

我只是想知道之间的区别。 c>。

I just wanted to know the difference between . operator and :: operator?

)用于访问对象的成员,后者(双冒号, :: )用于访问命名空间或类的成员。

The former (dot, .) is used to access members of an object, the latter (double colon, ::) is used to access members of a namespace or a class.

请考虑以下设置。

namespace ns {
    struct type
    {
        int var;
    };
}

在这种情况下,要引用结构命名空间,则使用 :: 。要访问类型类型的对象中的变量,请使用

In this case, to refer to the structure, which is a member of a namespace, you use ::. To access the variable in an object of type type, you use ..

ns::type obj;
obj.var = 1;

这篇关于点运算符和范围解析运算符之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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