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 complete name of the :: symbol in the last 2 lines?
The Scope Resolution Operator in C++ Two colons (::) are used in C++ as a scope resolution operator. This operator gives you more freedom in naming your variables by letting you distinguish between variables with the same name.
The double colon ( :: ) may refer to: an analogy symbolism operator, in logic and mathematics. a notation for equality of ratios.
In C++, scope resolution operator is ::. It is used for following purposes. 1) To access a global variable when there is a local variable with same name: // C++ program to show that we can access a global variable. // using scope resolution operator :: when there is a local.
It's commonly used to pack lots of values into an integral type. In your particular case, it defining the structure of a 32-bit microcode instruction for a (possibly) hypothetical CPU (if you add up all the bit-field lengths, they sum to 32).
What is the complete name of the
::
symbol in the last 2 lines?
It's "scope resolution operator".
Does anyone know the answer?
Yes.
Is this the weirdest question you ever been asked?
No.
It's called the scope resolution operator.
It's called scope resolution operator.
::
? Well, there is no alternative that always works. For your example, it is possible to just define those member functions in the body of your class, that would be the inline-style of defining a class:
class A{
int value;
public:
A() {
value = 0;
}
void print() {
cout << value << endl;
}
};
That way, you obviously have no way to put the definition in a different file, so it's not possible to compile them separately.
At other times, when ::
is used to resolve a namespace
rather than a class
, you can replace that with either reopening that namespace or pulling it into scope with using namespace
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With