global-namespace

Why is including “using namespace” into a header file a bad idea in C++?

ぃ、小莉子 提交于 2019-11-26 15:24:55
While reading from Bruce Eckel's "Thinking in C++" about namespaces, I encountered the following statement: However you'll virtually never see a using directive in a header file (at least not outside of scope). The reason is that using directive eliminate the protection of that particular namespace, and the effect last until the end of current compilation unit. If you put a using directive (outside of a scope) in a header file, it means that this loss of "namespace protection" will occur within any file that include this header, which often mean other header files. Would you please like to

Why is including “using namespace” into a header file a bad idea in C++?

对着背影说爱祢 提交于 2019-11-26 04:24:47
问题 While reading from Bruce Eckel\'s \"Thinking in C++\" about namespaces, I encountered the following statement: However you\'ll virtually never see a using directive in a header file (at least not outside of scope). The reason is that using directive eliminate the protection of that particular namespace, and the effect last until the end of current compilation unit. If you put a using directive (outside of a scope) in a header file, it means that this loss of \"namespace protection\" will

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