3729

On namespace 'names': ::std:: vs std::

Question:

I have been looking over some posts here on Stackoverflow, and I have noticed that most people use std:: but some people uses ::std::

I think i have read something about a <em>global scope</em> or something like that in namespaces as a reason to use ::std:: (but i can't find it now, because it was in a comment to an unrelated question)

Is there any reason to prefer one way versus the other?

Answer1:

It's a bad idea to write code like this, but you <em>could</em>:

namespace foo { namespace std { int bar; } std::string s; }

In that case, the std::string refers to the ::foo::std namespace, not the ::std namespace. So, using ::std::string is just being a little bit more unambiguously careful.

Recommend

  • App Script: How to view PDF of Google Sheet after function to save to Google Drive?
  • Pretty good heuristic evaluation rules for big TicTacToe 5x5 board
  • Receive .txt file from parse.com and place in textview
  • Git Staged - It have file history? [closed]
  • Google Analytics v4 in Android: Could not find class 'com.google.android.gms.analytics.Tracker&
  • How many wiki instances to install?
  • How to deal with xxx~HEAD after git merge?
  • Describe the .NET assembly circular dependency problem in layman's terms
  • Why is the COM interface contract immutable?
  • How do I customize header and footer in jqgrid?
  • How to stop a goroutine that is listening for RethinkDB changefeeds?
  • Deployments not visible in Kubernetes Dashboard
  • Making Cross Site Asynchronous HTTP Post from GWT Client
  • Connect Node.js with Oracle on Windows platform
  • Should I be afraid to use UDP to make a client/server broadcast talk?
  • How do I translate LR(1) Parse into a Abstract syntax tree?
  • JSON encode and decode on PHP
  • Using $compile in a directive triggers AngularJS infinite digest error
  • Updating Dojo provide
  • Git describe fails to return most recent annotated tag
  • Trying to get the char code of ENTER key
  • Using Sax parsing to edit and write XML in VB6
  • Debug.DrawLine not showing in the GameView
  • Custom Tabgroup Appcelerator
  • Yii2: Config params vs. const/define
  • $wpdb not working in file of WordPress plugin
  • Is it possible to access block's scope in method?
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Microsoft Visual Studio Community 2015 always crashes in Windows 10 if swithed to Visual FoxPro
  • Arrays break string types in Julia
  • bootstrap to use multiple ng-app
  • Java static initializers and reflection
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • reshape alternating columns in less time and using less memory
  • How can i traverse a binary tree from right to left in java?