473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

About namespace statements?

itiger
12
Does the Namespace Statments for e.g.
Expand|Select|Wrap|Line Numbers
  1. using namespace std;
  2.  
causes the compiler to load anything additional into the working memory. Does it has any effect on programs execution.
Or it only allows you to use the short class names in source program.
Jan 10 '11 #1

✓ answered by weaknessforcats

namespaces are tp prevent collisions when yu use names that are the same as someone else's. All names need to be unique.

Suppose you have a variable called cout. That would conflict with the cout that's part of C++ so you put your variable in a namespace:

Expand|Select|Wrap|Line Numbers
  1. namespace MyStuff
  2. {
  3.    int cout;
  4. }
Now you can code:

Expand|Select|Wrap|Line Numbers
  1. MyStuff::cout = 10;
and still use the C++ cout:

Expand|Select|Wrap|Line Numbers
  1. std::cout << MyStuff::cout << std::endl;
The preferred technique is to precede each variable with it's namespace as above.

The next worst thing to do is put a "using" declaration at the beginning of each function. But that may not resolve collisions within that function.

The next worst thing to do is to place a "using" declaration at the beginning of the file since that would permit collisions to all functions in that file.

And the biggest no-no of all is to put the "using" declaration in a header file that is included all over the place. That would permit collisions in all of your code.

1 1231
weaknessforcats
9,208 Expert Mod 8TB
namespaces are tp prevent collisions when yu use names that are the same as someone else's. All names need to be unique.

Suppose you have a variable called cout. That would conflict with the cout that's part of C++ so you put your variable in a namespace:

Expand|Select|Wrap|Line Numbers
  1. namespace MyStuff
  2. {
  3.    int cout;
  4. }
Now you can code:

Expand|Select|Wrap|Line Numbers
  1. MyStuff::cout = 10;
and still use the C++ cout:

Expand|Select|Wrap|Line Numbers
  1. std::cout << MyStuff::cout << std::endl;
The preferred technique is to precede each variable with it's namespace as above.

The next worst thing to do is put a "using" declaration at the beginning of each function. But that may not resolve collisions within that function.

The next worst thing to do is to place a "using" declaration at the beginning of the file since that would permit collisions to all functions in that file.

And the biggest no-no of all is to put the "using" declaration in a header file that is included all over the place. That would permit collisions in all of your code.
Jan 10 '11 #2

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

Similar topics

2
by: Jamie Chen | last post by:
Hello, need some help to understand this.(I am using DevSutio.Net) I set the default name space to be "http://www.w3.org/2001/XMLSchema" in my XML schema and I use my XML schema as the default...
2
by: C# newbie | last post by:
Hi guys, Something werid happening to me. When I run a query against every xml I have, below query works fine and returns what it should be returned. but there is another xml file as below,...
4
by: ad | last post by:
Is there any difference about namespace between VB.NET and C#. All functions in c# must include in a namespace. Why I can't find namespace in the files .vb . How VB.NET implement the...
5
by: ad | last post by:
Is there any difference about namespace between VB.NET and C#. All functions in c# must include in a namespace. Why I can't find namespace in the files .vb . How VB.NET implement the...
18
by: SpiralCorp | last post by:
int divide (int a, int b) { int r; r=a/b; return (r); } int main () { int result = divide (20,4); cout << result
4
by: 322322 | last post by:
Could anybody tell where is the namespace std file ? Thanks a lot ! namespace::std{ ..... .... }
0
by: Gary Herron | last post by:
Ohad Frand wrote: There is no way you can consider 'elif', 'else', 'except', and 'from' statements. However, as someone pointed out, the kwlist from the keyword module is the closest thing we...
0
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
2
by: rashmi55 | last post by:
Respected sir tlhintoq, i really don't know about how to ask question. sorry for asking like order. it will never happen again. I want to know briefly about namespace in C#.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.