ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Home
Upgrade
Credits
Help
Search
Awards
Achievements
 2273

Something I realized about the standard namespace

by IcyJake - 06-15-2018 - 01:21 AM
#1
So, as you guys probably know, I recently found out something about the standard namespace (aka "using namespace std;"). I realized that using the standard namespace can actually be bad practice because it can be referred to as "global namespace pollution". This means that you may run into problems whenever you have multiple namespaces that contain an identical function name with signature, so it would be kind of obscure for the compiler to be able to choose which one it would call, but this can be bypassed by designating the namespace with your function call, like this:

Code:
std::cout

Or, if you don't want to type 'std::', then you can just do something like this:

Code:
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    cout << "Hello, world!";

    return 0;
}

Some of you probably already knew this and these "problems" are pretty much an uncommon thing to come across in the first place, but I just thought I would share it with you guys anyways. Peace. :P
Reply
#2
thanks for share~
Reply

Users browsing: 1 Guest(s)