![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 11
Rep Power: 0
![]() |
I've been hearing a lot about "Namespaces" here and online tutors so what exactly are they for & why? They sound kind of abstract. What's the best way to visualize them for?
|
|
|
|
|
|
#2 |
|
Man Bear Pig Hunter
Join Date: Jul 2005
Location: NorCal, USA
Posts: 290
Rep Power: 4
![]() |
Think of a Namespace as a name for that file for the code to reffer itself to with out using file names. Best Answer I have for you, sorry.
|
|
|
|
|
|
#3 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 291
Rep Power: 4
![]() |
If you are working with two (or more) external libraries, and they both have a class named for example Vector3, and you want to create a Vector3 object. Which constructor do your object use then? A conflict will appear.
The solution to this is to use namespaces, so the consturctors got different names, and wont collide. Physics::Vector3 myVector; Renderer::Vector3 myVector2; |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
A nice, previous treatement on the forum can be found here .
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 927
Rep Power: 4
![]() |
The simple answer is that a namespace is a context in which symbols (names of variables, functions, classes, etc) reside. It is similar to how you might refer to your house as 'home', and I refer to mine as 'home'. Yet when you say 'home', I don't think you're talking about my house, and vice versa. In C++ syntax, we would refer to those symbols as BrinyCode::home and lectricpharaoh::home. The full name allows us to avoid the ambiguity that would otherwise occur. C++ namespaces are a mechanism for resolving such ambiguities in code. Other languages have their own mechanism, such as packages in Java, that perform pretty much the same job. Some languages, like C, don't have any such mechanism, which means you're more likely to run into naming conflicts.
For a more comprehensive discussion, see the link that DaWei posted.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
#6 |
|
Man Bear Pig Hunter
Join Date: Jul 2005
Location: NorCal, USA
Posts: 290
Rep Power: 4
![]() |
They beat my answer to $#%....much better job explain guys, good work =)
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
very informative indeed.
p.s. @ ghost, animated avatars are not allowed. even though they're cool. ![]()
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#8 |
|
Man Bear Pig Hunter
Join Date: Jul 2005
Location: NorCal, USA
Posts: 290
Rep Power: 4
![]() |
are they really not allowed? that is weird and kind of sad, whats the reasoning?
|
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
It's simple, really, Ghost. Some animated avatars may be overly distracting. Others could conceivably trigger epileptic reactions. It's best not to ask the moderators to decide where to draw those lines. It's easier to just draw the line at "none". Shoot, I had one, myself. I'm doing okay without it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 | |
|
Programmer
Join Date: Oct 2005
Posts: 49
Rep Power: 0
![]() |
Quote:
![]()
__________________
Dylan Ferguson hence the nickname D-Ferg Got an IPod? Use ManagePod All the cool kids are doing it. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|