+ 1

Why the :: before size on line 22?

https://code.sololearn.com/cpl4iFL4T4E7/?ref=app

19th Jul 2019, 9:15 PM
Vincent Maestro
Vincent Maestro - avatar
5 odpowiedzi
+ 7
:: is scope resolution operator. Here it is used to access global variable(size) value.
19th Jul 2019, 9:25 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 5
The compilation error regarding ambiguity when the scope resolution operator is removed is due to the function size() defined under the std namespace, introduced in C++17. It returns the size of an STL like container. ( https://en.cppreference.com/w/cpp/iterator/size ) Unless there is an ambiguity, you need not use the scope resolution operator to use a global variable. But it is always better to define local variables instead, or use a namespace or class for the same. This is why 'using namespace' statements is a bad idea.
20th Jul 2019, 2:38 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
On code playground, if I remove :: the code does not run as it claims that the reference to size is ambiguous.
20th Jul 2019, 12:34 AM
Sonic
Sonic - avatar
+ 1
I Know it's the scope resolution operator. Just that I once removed it and I stopped seeing special characters like "*#^..." In the password but after running it again and they appear
19th Jul 2019, 9:30 PM
Vincent Maestro
Vincent Maestro - avatar
+ 1
Anyway thanks guys
19th Jul 2019, 9:30 PM
Vincent Maestro
Vincent Maestro - avatar