The full name of the double colon in C ++

If I have a class:

class A{ public: A(); void print(); private: int value; }; A::A() {value = 0;} void A::print() {cout << value << endl;} 

What is the full name of the symbol :: in the last two lines?

+6
source share
3 answers

It is called a region resolution operator.

+12
source

What is the full name of the symbol :: in the last two lines?

This is the "scope statement".

Does anyone know the answer?

Yes.

Is this the strangest question you have ever asked?

Not.

+14
source

It is called a region resolution operator.


Would you like to know what you could write instead of :: ? Well, there is no alternative that always works. For your example, you can simply define those member functions in the body of your class that would be the built-in style of class definition:
 class A{ int value; public: A() { value = 0; } void print() { cout << value << endl; } }; 

Thus, you obviously have no way to put the definition in another file, so they cannot be compiled separately.

At the same time, when :: used to solve the namespace , not the class , you can replace it with either re-opening this namespace or pulling it into scope with using namespace .

+7
source

Source: https://habr.com/ru/post/917569/


All Articles