By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

What are the advantages ans disadvantages of employing the

P: 1
What are the advantages ans disadvantages of employing the "using"
Jan 13 '18 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
C++ requires that all names must be unique. To avoid name clashes you place names inside namespaces:

Expand|Select|Wrap|Line Numbers
  1. int x;
  3. namespace system
  4. {
  5. struct data
  6. {
  7. int a,b,c;
  8. datat x;
  9. }
  10. namespace mystuff
  11. {
  12. double x;
  13. }
These are three different variables with names of:


So far so good. Now letís say you donít like all this :: stuff in the variable name so you can tell the compiler to check a namespace for the variable name:

Expand|Select|Wrap|Line Numbers
  1. using namespace system;
Now instead of coding system::x all you need is x because you have told the compiler you are using namespace system.

Expand|Select|Wrap|Line Numbers
  1. x= 10;
However, this x might be ::x or system::x. If the x is ::x this code compiles. If the x is system::x, the code does not compile.

The using directive is for lazy programmers only. Top be safe you should always use fully qualified names in your
Jan 13 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.