|
c++ namspaces
|
|
02-15-2010, 01:02 AM
(This post was last modified: 02-15-2010 02:29 AM by drdebcol.)
Post: #1
|
|||
|
|||
|
c++ namspaces
Namespaces
Namespaces address the problem of naming conflicts between different pieces of code. For example, you might be writing some code that has a function called foo(). One day, you decide to start using a third- party library, which also has a foo() function. The compiler has no way of knowing which version of foo() you are referring to within your code. You can’t change the library’s function name, and it would be a big pain to change your own. Namespaces come to the rescue in such scenarios because you can define the context in which names are defined. To place code in a namespace, simply enclose it within a namespace block: Code: // namespaces.hmycode::foo(); // Calls the “foo” function in the “mycode” namespace Any code that falls within a “mycode” namespace block can call other code within the same namespace without explicitly prepending the namespace. This implicit namespace is useful in making the code more precise and readable. You can also avoid prepending of namespaces with the using directive. This directive tells the compiler that the subsequent code is making use of names in the specified namespace. The namespace is thus implied for the code that follows: Code: // usingnamespaces.cpp |
|||
|
02-15-2010, 02:31 AM
Post: #2
|
|||
|
|||
|
RE: c++ namspaces
Very good explanation. Namespaces are really important part of C++ !
OFFTOPIC : I edited your post because you used php tags and that made post too long to the right because text inside was too long to the right. So i used simple code tags where codes are. "I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein |
|||
|
« Next Oldest | Next Newest »
|






