Why does C need the scope resolution operator

0 votes

Why is the:: operator used in C++ instead of the. operator for this purpose? 

There is no distinct operator in Java, and it works great. 

Is there a distinction between C++ and Java that necessitates the use of a separate operator in order for C++ to be parsable?

My only idea is that:: is required for precedence reasons, but I'm not sure why it should take precedence over, say,... 

The only way I can see it happening is if something like

a.b::c;

would be parsed as

a.(b::c);

, but I can't think of a situation where this syntax would be lawful in any case.

Maybe "they do different things, so they might as well look different" is the case. 

That, however, does not explain why : : has higher priority than.

Jun 1 in C++ by Nicholas
• 2,260 points
13 views

1 answer to this question.

0 votes
No. There is no scope resolution operator in C.

One can be found in C++ (::).

Perhaps you (or your book) are mixing up C and C++.

You inquired how to get to the global variable a from a function (here main) having its own local variable a.

This isn't possible in C.

It's lexically incorrect.

Of course, you could take the variable's address from somewhere else and use it as a pointer, but that's a different story.

Simply rename the variable to something like 'don't do that.'
answered Jun 1 by Damon
• 3,380 points

Related Questions In C++

0 votes
0 answers

Using :: (scope resolution operator) in C++

I'm studying C++ and I never know ...READ MORE

5 days ago in C++ by Nicholas
• 2,260 points
7 views
0 votes
1 answer

The Definitive C++ Book Guide and List

For Beginner (includes those without coding experience) Programming: ...READ MORE

answered Jun 6 in C++ by pranav
• 2,320 points
21 views
0 votes
0 answers

What is the C++ function to raise a number to a power?

What's the best way to raise a n ...READ MORE

Jun 1 in C++ by Nicholas
• 2,260 points
17 views
0 votes
1 answer

C++ binary operator overloading

The language defines several fundamental types, such as int and double.  Objects are instances of fundamental kinds. Let's pretend you have: struct Foo { ... }; You can use non-member functions to overload the operator+ function. Foo operator+(Foo , ...READ MORE

answered 6 days ago in C++ by Damon
• 3,380 points
19 views
0 votes
1 answer
0 votes
1 answer

what are "and" and "or" operators in Python?

AND - True if both the operands ...READ MORE

answered Apr 18, 2018 in Python by Johnathon
• 9,090 points
256 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 58,080 points
190 views
0 votes
1 answer

How to write "not equal" in python?

The keywords is and is not are ...READ MORE

answered Sep 18, 2018 in Python by SayantiniDeb
• 200 points
1,527 views
0 votes
1 answer

why are copy constructors needed and what are the cases where they are very helpful?

A copy constructor is a member function ...READ MORE

answered May 31 in C++ by Damon
• 3,380 points
32 views
0 votes
1 answer

The new syntax "= default" in C++11

A defaulted default function Object() { [native code] } is defined as a user-defined default function Object() { [native code] } with an empty compound statement and no initialization list. I'll give you an example to demonstrate the difference: #include <iostream> using namespace std; class A { public: ...READ MORE

answered Jun 7 in C++ by Damon
• 3,380 points
11 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP