c ++中的“::”“。”和“ - >”之间的区别 [英] Difference between “::” “.” and “->” in c++

查看:305
本文介绍了c ++中的“::”“。”和“ - >”之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了Kwadrat类。作者使用三种类型的operator ::,。和 - >。箭头是唯一的工作。这三个之间有什么区别?

I have found the class Kwadrat. The author used three types of operator ::, . and ->. The arrow is the one that only works. What's the difference between those three?

#include <iostream>

using namespace std;

class Kwadrat{
public:
int val1, val2, val3;
    Kwadrat(int val1, int val2, int val3)
    {
        this->val1 = val1;
        //this.val2 = val2;
        //this::val3 = val3;
    }
};

int main()
{
    Kwadrat* kwadrat = new Kwadrat(1,2,3);
    cout<<kwadrat->val1<<endl;
    cout<<kwadrat->val2<<endl;
    cout<<kwadrat->val3<<endl;
    return 0;
}


推荐答案


  • :: 命名空间中的类型,命名空间中的变量,类中的静态变量或类中的类型。

  • 命名实例变量或成员函数

  • a-> b (* a).b 的语法糖。

    • :: names a type within a namespace, a variable within a namespace, a static variable in a class, or a type in a class.
    • . names an instance variable or member function
    • a->b is syntactic sugar for (*a).b.
    • 这篇关于c ++中的“::”“。”和“ - &gt;”之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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