What are namespaces ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What are namespaces ?

why we use......using namespace std;....??

29th Jul 2016, 2:51 PM
Sparsh Juneja
Sparsh Juneja - avatar
5 Answers
+ 1
a namespace is items used to set objects so they can be used over again by name. Namespace std makes it to where we don't have to write std::cout when trying to print or std::cin when wanting someone to input.
29th Jul 2016, 3:06 PM
Jaque
Jaque - avatar
+ 1
yes
29th Jul 2016, 4:03 PM
Jaque
Jaque - avatar
+ 1
Namespaces are a way of preventing so called "name collision", i.e. multiple *definition* (not necessarily declaration) of the same symbol. This can occur in projects that are bigger than these presented here at SoloLearn C++ as homonyms become more likely to occur. A term is a homonym if this term is used in different meanings. It's the opposite of synonyms which denote different words for the same meaning. An example: the word "bow" can mean the thing you use to play a violin or a (medieval) weapon. You could want to write a, let's say, role-playing game set in the middle ages. Then you might want to model in your code the weapon *and* the music utility. In order to distinguish between the weapon and the music utility without changing the name of the classes, you put one bow class in the namespace music and the other in the namespace weapon.
29th Jul 2016, 6:10 PM
Stefan
Stefan - avatar
0
object oriented programme
29th Jul 2016, 3:23 PM
Karnakanti Rashmitha
Karnakanti Rashmitha - avatar
0
Can namespaces be applied to importing a function and not a library?
29th Jul 2016, 3:55 PM
SouthBay
SouthBay - avatar