What is the :: operator used for? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 3

What is the :: operator used for?

I am learning C++ now, but in the tutorial I didn't quite understand what this operator means. Could you please explain?

10th May 2018, 9:26 AM
Arc
Arc - avatar
10 Respuestas
+ 6
It is the scope resolution operator, which is used to specify the context of the method/member/variable you are trying to invoke. Wiki contains a pretty good example with explanations. https://en.m.wikipedia.org/wiki/Scope_resolution_operator Also worth taking a look at: https://code.sololearn.com/ca0X1CRI8ZoS/?ref=app
10th May 2018, 9:47 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
:: is called "Scope resolution operator". For example, you have the following class: class SoloLeaner { int id; string name; public: void introduce(); }; // Suppose you want to define introduce() member function "outside of the block" of SoloLeaner class. Then, :: operator would be useful. void SoloLeaner :: introduce() { cout << "Hi, I am " << name << " and my ID is private"; }
10th May 2018, 9:52 AM
777
777 - avatar
+ 4
it is called "Scope resolution operator" and it is denoted by:: it is used to call a variable that is declared outside main and if same variable is decalred inside then this operator is used ti differntiate between these two variable
11th May 2018, 7:05 AM
Sanju Jose
Sanju Jose - avatar
+ 2
scope resolution operator suppose you have two variables named a, one is global and the other one is local. so if you want to change value of local a a=7 but if you want to change/access value of global a ::a=7 //changes value of global variable
10th May 2018, 9:49 AM
‎ ‏‏‎Anonymous Guy
+ 2
it is a scope resolution operator. it enables to use a member of a class outside of it's scope without instantiating an object.
10th May 2018, 10:38 AM
Param🇮🇳
Param🇮🇳 - avatar
10th May 2018, 11:21 AM
‎ ‏‏‎Anonymous Guy
+ 2
in a development,you have your team to develop code on the basis of seperate modules... it may be possible that two team members define classes with same names. To prevent code collision and to provide modularity, namespace are used.
10th May 2018, 11:22 AM
Param🇮🇳
Param🇮🇳 - avatar
+ 1
it is scope resolution operator and is used to represent a global variable or a variable declared outside a fuction or class
11th May 2018, 7:25 AM
Yash Nirmal
Yash Nirmal - avatar
0
Thank you very much for your answers☺
10th May 2018, 11:11 AM
Arc
Arc - avatar
0
@Hatsy Rei What is actually a nameapace?
10th May 2018, 11:12 AM
Arc
Arc - avatar