hi every body!
1. I'm really confused by the use of namespace how do namespace avoid name conflict? If I could use different names how could be any conflict.
hi every body!
1. I'm really confused by the use of namespace how do namespace avoid name conflict? If I could use different names how could be any conflict.
Sometimes it's convinent to use different names, but sometimes it's not, especially if you're trying to write intuitive code. When it's not, you encapsulate it into a namespace to avoid name collisions. Think of a namespace as an uninstantiatible class with only public static members.
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
A simple example:
Code:int x; int x; // == BAD namespace a { int x; } namespace b { int x; } int main() { a::x = 2; b::x = 3; return 0; } // == GOOD
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
You may be able to only use unique names in your code, but what if you want to use some code from other people, too? You'd have to go through it and remember all the names in it so that they don't clash with yours.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Thank you!
Thanks, that made me understand it tooOriginally Posted by CornedBee
-Webmaster-
http://www.koaworld.com
Pr0gr4m|\/|1Ng n00b
#include <iostream>
using namespace std; // what variable?
namespace A {
int Var1;
char Var2;
char var3;
}
int main () {
int Var1 = 200;
A::Var1 = 100;
return 0;
}
My question is. What are the variables when we say using namespace std
The using namespace std, is for the standard functions. Like cout,cin,string,ect.
By putting that using namespace std at the top of your source you are making that the global namespace.
Woop?
know it is more clear! Thank You!