一、(:: operator)解决局部变量与全局变量重名问题

1 int var = 10;
2 int main()
3 {
4     int var = 8;
5     cout<<var<<endl;//local variable
6     cout<<::var<<endl;//global variable
7 
8     return 0;
9 }

(:: operator)作用域限定符的几种使用

 

二、引用命名空间内的名字

  例如:using std::cout;

     using std::endl;

 

三、类成员的限定

  1、类中静态成员的使用

    class A 

    {

      public:

        void DisPlay();

        static int a = 10;

    };

    cout<<A::a<<endl;

  2、类成员函数在类外实现

  void A::DisPlay()

  {

    ......

  }

 

相关文章:

  • 2021-12-01
  • 2021-10-24
  • 2022-12-23
  • 2021-09-06
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案