1.

How do you refer to a name of class or function that is defined within a namespace?

Answer»

There are two ways in which we can refer to a name of class or function that is defined within a namespace: Using scope resolution OPERATOR ‘::’ through the using keyword. This is shown in following example:

There are two ways in which we can refer to a name of class or function that is defined within a namespace: Using scope resolution operator through the using keyword. This is shown in following example:                              namespace name1                              {                              class sample1                              {                              // code                              } ;                              }                             namespace name2                              {                              class sample2                              {                              // code                              } ;                              }                              using namespace name2 ;                              VOID main( )                              {                              name1::sample1 S1 ;                              sample2 s2 ;                              } Here, class sample1 is referred using the scope resolution operator.

On the other hand we can directly refer to class sample2 because of the statement using namespace name2 ; the using keyword declares all the NAMES in the namespace to be in the current scope. So we can USE the names without any qualifiers.

Here, class sample1 is referred using the scope resolution operator. On the other hand we can directly refer to class sample2 because of the statement using namespace name2 ; the using keyword declares all the names in the namespace to be in the current scope. So we can use the names without any qualifiers.



Discussion

No Comment Found