On 25/09/2019 10:02, Frederick Gotham wrote:
>
> Occasionally I see people write code like this:
>
> #include <string>
>
> int main()
> {
> ::std::string str;
> }
>
> I think you would only ever need to put those two colons before 'std' if you created a class or a namespace called 'std', and of course if you did, then it would have to be inside another namespace (because otherwise you'd have a name clash).
>
> I tried compiling the following code, and each time it created a 'string' from the C++ standard library.
>
> So the question I ask is if there is **ever** any situation when it's necessary to put two colons before 'std'?
>
I believe it is possible to cause conflicts with "std" that could be
avoided by using "::std". But it would have to be malicious and
carefully crafted, or totally inept and highly unlucky. Since there are
few programmers in either category, and if you have either type in your
team then you have far bigger problems than can be solved with "::std",
it is basically a non-issue.
Some people in this group use it, but IMHO it is more about making the
code /look/ like it is super-robust, than actually being good practice.
The drop in readability is not justified by the miniscule improvement
in robustness or portability.