- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Scope Resolution Operator vs this pointer in C++
Scope Resolution Operator is used to access static or class members whereas this pointer is used to access object members when there is a local variable with same name.
Scope Resolution operator
Example
#include<iostream> using namespace std; class AB { static int x; public: // Local parameter 'x' hides class member // 'x', but we can access it using ::. void print(int x) { cout<<"the number is:" << AB::x; } }; // static members must be explicitly defined like below in c ++ int AB::x = 7; int main() { AB ob; int m = 6 ; ob.print(m); return 0; }
Output
the number is:7
this pointer
Example
#include<iostream> using namespace std; class AB { int x; public: AB() { x = 6; } // here Local parameter 'x' hides object's member // 'x', we can access it using this. void print(int x) { cout<<"the number is: " << this->x; } }; int main() { AB ob; int m = 7 ; ob.print(m); return 0; }
Output
the number is: 6
- Related Articles
- Scope Resolution Operator Versus this pointer in C++?
- C++ Scope resolution operator
- Scope resolution operator in C++
- PHP Scope Resolution Operator (::)
- What is the scope resolution operator in C#?
- Why does C++ need the scope resolution operator?
- Where do we use scope Resolution Operator (::) in C#?
- What is the use of scope resolution operator in C++?
- Pointer vs Array in C
- What is pointer operator & in C++?
- What is Pointer operator * in C++?
- Passing by pointer Vs Passing by Reference in C++
- Ternary operator ?: vs if…else in C/C++
- Copy constructor vs assignment operator in C++
- Double Pointer (Pointer to Pointer) in C

Advertisements