what is namespace? what are the uses of namespace?
Namespaces allow to group entities like classes, objects
and functions under a name. This way the global scope can
be divided in "sub-scopes", each one with its own name.
The format of namespaces is:
namespace identifier
{
entities
}
Where identifier is any valid identifier and entities is
the set of classes, objects and functions that are included
within the namespace. For example:
namespace myNamespace
{
int a, b;
}
In this case, the variables a and b are normal variables
declared within a namespace called myNamespace. In order
to access these variables from outside the myNamespace
namespace we have to use the scope operator ::. For
example, to access the previous variables from outside
myNamespace we can write:
myNamespace::a
myNamespace::b
The functionality of namespaces is especially useful in the
case that there is a possibility that a global object or
function uses the same identifier as another one, causing
redefinition errors. For example:
// namespaces
#include <iostream>
using namespace std;
namespace first
{
int var = 5;
}
namespace second
{
double var = 3.1416;
}
int main () {
cout << first::var << endl;
cout << second::var << endl;
return 0;
}
5
3.1416
In this case, there are two global variables with the same
name: var. One is defined within the namespace first
and the other one in second. No redefinition errors happen
thanks to namespaces.
| Is This Answer Correct ? | 0 Yes | 0 No |
any one please tell me the purpose of operator overloading
WHEN A COPY CONSTER IS CALL ?
I hv a same function name,arguments in both base class and dervied class, but the return type is different. Can we call this as a function overloading? Explain?
How do you answer polymorphism?
Which language is not a true object oriented programming language?
What is class and object in oops?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
In multilevel inheritance constructors will be executed from the .... class to ... class
Why polymorphism is used in oops?
1. Define a class.
What is the difference between the c++ & java?
What is Virtual Keyword?