Login Register






Something I realized about the standard namespace filter_list
Author
Message
Something I realized about the standard namespace #1
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 may 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.
(This post was last modified: 11-01-2023, 06:47 AM by Confidential.)

Reply

RE: Something I realized about the standard namespace #2
I haven't used std yet as a learner but, seems interesting to read thou Smile
(This post was last modified: 06-15-2018, 01:18 AM by Vultra.)

Reply

RE: Something I realized about the standard namespace #3
This problem is solved entirely if you treat it like it were C, and follow these rules:

1. only include files you absolutely need
2. fully qualify everything

With C++, rule #1 gets gummed up, because C++ programmers being retarded tend to put everything into one header file. The concept of namespaces in the first place was to combat this problem.

Reply