![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,206
Rep Power: 5
![]() |
The original question was not that clear, Jimbo.
Some people, when they have nothing to say, point out the irrelevant, eh tempest? |
|
|
|
|
|
#12 |
|
Newbie
Join Date: Feb 2006
Posts: 18
Rep Power: 0
![]() |
It might appear completely unrelated to you Grumpy, but I am new to namespaces. So I was wondering why you did not use namespace std. Now I got the point. Using std:: exempts one from bringingwhole of namespace into the scope.
|
|
|
|
|
|
#13 | ||
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,206
Rep Power: 5
![]() |
Quote:
Quote:
A "using namespace" directive does not bring a namespace into scope. It actually tells the compiler that, if it encounters a name, that it should look within the namespace for candidates that match that name. A "using namespace std;" directive potentially exempts one from having to use the "std::" prefix to fully qualify a name (not the reverse, which you stated). I say potentially, because it can also introduces ambiguity. For example; #include <iostream>
using namespace std;
namespace X
{
int cout;
};
using namespace X;
int main()
{
cout << "Hello\n";
}int main()
{
std::cout << "Hello\n";
} |
||
|
|
|
|
|
#14 | ||
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
Quote:
__________________
PFO - My daily dose of technology. |
||
|
|
|
|
|
#15 |
|
Newbie
Join Date: Feb 2006
Posts: 18
Rep Power: 0
![]() |
using namespace std;
namespace X
{
int cout;
};What is namespace X for, as we are already using namespace std?Is it a namespace in a namespace? |
|
|
|
|
|
#16 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#17 |
|
Newbie
Join Date: Feb 2006
Posts: 18
Rep Power: 0
![]() |
Thanx InfoGeek. I got a basic idea of namespaces.
|
|
|
|
|
|
#18 |
|
Newbie
Join Date: Feb 2006
Posts: 18
Rep Power: 0
![]() |
Correction: I meant using namespaces. Sorry.
|
|
|
|
|
|
#19 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,206
Rep Power: 5
![]() |
namespace X was a namespace I used in the example to illustrate one of the problems that can be cased by "using namespace" directives. The purpose of namespaces is to allow a program to use multiple things with the same name (eg cout in my example), as long as the things with the same name are placed into different namespaces. A using directive can work against that purpose (and confuse the compiler) if not used carefully.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|