¡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?
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
+ 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";
}
+ 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
+ 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
+ 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.
+ 2
+ 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.
+ 1
it is scope resolution operator and is used to represent a global variable or a variable declared outside a fuction or class
0
Thank you very much for your answers☺
0
@Hatsy Rei
What is actually a nameapace?