Jump to content

  • Log In with Google      Sign In   
  • Create Account

whats namespace?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 mad_hatter   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 January 2002 - 04:05 AM

Whats namepace?

Sponsor:

#2 evaclear   Members   -  Reputation: 162

Like
Likes
Like

Posted 12 January 2002 - 07:07 AM

A name space is something that was added to the C++ language in order to easily let people inter mix libraries.

Lets say you''ve downloaded 2 math libraries for your game.

"MathLibrary" and "MathPlus". Each of these libraries have functions to do multiplication, and other types of math. So they have many of the same function names.

Example:
MathLibrary''s multiply function looks like this:
Multiply(int value1, int value2, int &result);

MathPlus''s multiply function looks like this:
Multiply(int value1, int value2, int &result);

However lets say that by testing the two libraries out you''ve determined that MathLibraries divide function is 2x faster than MathPlus''s but MathPlus''s multiply is 2x faster than MathLibraries.

You''ve got a bit of a problem on your hands. You can''t include both libraries because they have the same function names and return values. This is where namespaces become useful. You can include both header files, and then call the functions like this:

MathPlus::Multiply();
or
MathLibrary::Divide();

If you want to use math plus''s math functions for the majority of your program with out refering to the namespace again you can put this under the include files

using namespace MathPlus;

Now you can call
Multiply() and it will be the same as calling MathPlus::Multiply, and you can still refrence MathLibraries divide function by doing MathLibrary::Divide();

I realize that the multiply and divide examples are a bit lame considering C++ has built in functionality for them already, but I thought it would be a good example of how and why you might use namespaces.









Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS