This question already has an answer here:
using ::std::...;
VS
using std::...;
Is there a difference(s)? If so, which one(s)?
I saw this:
using ::std::nullptr_t;
which made me wonder.
This question already has an answer here:
VS
Is there a difference(s)? If so, which one(s)? I saw this:
which made me wonder. |
||||
marked as duplicate by chue x, Roddy of the Frozen Peas, Deduplicator yesterdayThis question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. |
||||
In your case, there is most likely no difference. However, generally, the difference is as follows:
|
|||||
|
If you are inside another namespace that has its own nested
Though definitely not a good practice to ever have a nested |
|||
From: http://en.cppreference.com/w/cpp/language/using_declaration
Therefore, if your current scope already has a class with the same name, there will be an ambiguity between the one you introduced and the one in your current namespace/block. A using declaration is just a subset of a using directive. The using directives is defined as follows (http://en.cppreference.com/w/cpp/language/namespace):
Thus, you can consider these two examples that display the issues that can arise. It prevents ambiguity between namespaces that share the same name (example 1) as well as ambiguity between class names in different namespaces (example 2).
Consider this example which showcases why people shun the use of
|
|||||||||||||
|
It depends on where you use the
it will not compile unless you inform the compiler to search the global namespace -> std namespace -> vector in your declaration by stating |
|||||||||||||
|
::std::nullptr_t
only if someone else adds anotherstd::nullptr_t
to a nested namespace inside your project. Or you could let your manager have a serious talk to that guy. – Bo Persson yesterdaynamespace C14_compatibility { namespace std { template <typename T> using decay_t = typename decay<T>::type; }}
andusing namespace C14_compatibility;
seems a possible usage. – Jarod42 yesterday