Reputation: 3914
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?
Upvotes: 6
Views: 1310
Reputation: 120711
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
.
Upvotes: 7
Reputation: 234434
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.
Upvotes: 15