Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Programming

FORUM Dedicated to Programming
 
HomePortalLatest imagesSearchRegisterLog in

 

 What is namespace in C++ ?

Go down 
AuthorMessage
Admin
Administrator
Administrator



Number of posts : 22
Age : 34
Registration date : 2008-11-12

What is namespace in C++ ? Empty
PostSubject: What is namespace in C++ ?   What is namespace in C++ ? I_icon_minitime14/11/08, 07:00 pm

A namespace is a scope. Namespaces are used to make logical groupings and to avoid potential naming conflicts within C++ applications. Use of namespaces incurs no overhead to application size or performance. To use the contents of a namespace, its contents or those parts of it that are required must be brought into current scope which can be achieved in a number of different ways:

eg. To bring an entire namespace into current scope, use the 'using' keyword, eg:

using namespace std;

This brings the whole of the standard template library (STL) into current scope. This is generally only used in examples; bringing the entire contents of such a namespace into current scope in this fashion defeats the purpose of namespaces. To bring a single namespace member into scope, the using keyword can be used to explicitly refer to that item, eg:

using std::string;

This brings the STL 'string' type into current scope. Alternatively you can simply declare your variable with full namespace syntax within code. eg:

std::string my_string;

This declares my_string as an object of the STL string type.
Back to top Go down
http://programming.forumakers.com
 
What is namespace in C++ ?
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Programming :: C & C++ Programming :: C & C++ Frequently Asked Questions-
Jump to: