Department of Computing Science & Engineering
Subject Name: OOPS Subject Code: BCS01T1004
CAT-3 Presentation
Topic Name-Namespaces in c++
Section: 3
HIMANSHUN SENGAR 21SCSE1010503
DIVYANSH PRATAP SINGH 21SCSE1010606
ADITYA KUMAR GUPTA 21SCSE1010838
Submitted to
Prof.(Dr.) PRAVESH TANWAR
Department of Computer Science & Engineering,
Galgotias University
Jj
NAMESPACES IN
C++
CONTENT
INTRODUCTION
NAMESPACE
FUNDAMENTALS
NAMESPACE FEATURE
INTRODUCTION
DEFINATION
Namespaces allow us to group named entities that
otherwise would have global scope into narrower scopes,
giving them namespace scope. This allows organizing the
elements of programs into different logical scopes referred
to by names. Namespaces provide the space where we can
define or declare identifiers i.e. names of variables, methods,
classes, etc.
NAMESPACE FUNDAMENTALS
Namespace is a feature added in C++ and is not present in C.
A namespace is a declarative region that provides a scope to the
identifiers (names of functions, variables or other user-defined
data types) inside it.
Multiple namespace blocks with the same name are allowed. All
declarations within those blocks are declared in the named scope.
DEFINING A
NAMESPACE
A namespace definition begins with the keyword namespace followed
by the namespace name as follows:
namespace namespace_name{
// code declarations i.e. variable (int a;)
method (void add();)
classes ( class student{};)
}
using directives
The using directive allows all the names in a namespace to
be used without the namespace-name as an explicit
qualifier. Use a using directive in an implementation file (i.e.
*.cpp) if you are using several different identifiers in a
namespace; if you are just using one or two identifiers,
then consider a using declaration to only bring those
identifiers into scope and not all the identifiers in the
namespace. If a local variable has the same name as a
namespace variable, the namespace variable is hidden. It is
an error to have a namespace variable with the same name
as a global variable.
NAMESPACES FEATURES
The global namespace
If an identifier is not declared in an explicit namespace, it is part of
the implicit global namespace. In general, try to avoid making
declarations at global scope when possible, except for the entry
point main Function, which is required to be in the global
namespace. To explicitly qualify a global identifier, use the scope
resolution operator with no name.
The std namespace
All C++ standard library types and functions are declared in the std
Reference:
1.
2.
3.
Thank You…..