scope-resolution

What does the “::” mean in “::tolower”?

喜夏-厌秋 提交于 2019-11-27 14:51:47
问题 I've seen code like this: std::string str = "wHatEver"; std::transform(str.begin(), str.end(), str.begin(), ::tolower); And I have a question: what does mean :: before tolower? and std::tolower not works, but ::tolower works OK 回答1: Means that it is explicitly using the tolower in the global namespace (which is presumably the stdc lib one). Example: void foo() { // This is your global foo } namespace bar { void foo() { // This is bar's foo } } using namespace bar; void test() { foo(); //

Why does C++ need the scope resolution operator?

我的未来我决定 提交于 2019-11-26 14:29:07
(I know what the scope resolution operator does, and how and when to use it.) Why does C++ have the :: operator, instead of using the . operator for this purpose? Java doesn't have a separate operator, and works fine. Is there some difference between C++ and Java that means C++ requires a separate operator in order to be parsable? My only guess is that :: is needed for precedence reasons, but I can't think why it needs to have higher precedence than, say, . . The only situation I can think it would is so that something like a.b::c; would be parsed as a.(b::c); , but I can't think of any

Why does C++ need the scope resolution operator?

瘦欲@ 提交于 2019-11-26 03:55:30
问题 (I know what the scope resolution operator does, and how and when to use it.) Why does C++ have the :: operator, instead of using the . operator for this purpose? Java doesn\'t have a separate operator, and works fine. Is there some difference between C++ and Java that means C++ requires a separate operator in order to be parsable? My only guess is that :: is needed for precedence reasons, but I can\'t think why it needs to have higher precedence than, say, . . The only situation I can think

What is the meaning of prepended double colon “::”?

守給你的承諾、 提交于 2019-11-25 23:47:56
问题 I found this line of a code in a class which I have to modify: ::Configuration * tmpCo = m_configurationDB;//pointer to current db and I don\'t know what exactly means the double colon prepended to the class name. Without that I would read: declaration of tmpCo as a pointer to an object of the class Configuration ... but the prepended double colon confuses me. I also found: typedef ::config::set ConfigSet; 回答1: This ensures that resolution occurs from the global namespace, instead of starting