Write a simple program that has 3 variables named x that are

Write a simple program that has 3 variables named x that are each in separate namespaces.

Solution

2. Write a simple program that has 3 variables named x that are each in seperate namespaces

Answer:-

An earlier section (\"Storage Classes\" ) explains scope rules for variables in C++. Program variables :

1) Local (declared inside functions without static and exist in local stack frames)

2) External static with file scope (declared outside functions with static)

3) Global with program scope (declared outside functions without static)

4) Internal static (declared inside functions with static and exist in the data area)

program scope (3), separately compiled modules require access to function names, structures, and objects, often placed in global namespace. Global namespace includes all names from global declarations; that is, declarations appearing outside of function definitions. What is the proper way to deal with global namespaces.

Use Namespaces :

When programmers use separately compiled modules, name conflicts may occur in the global namespace. Consider the following geometry.h include file, for instance.

The compiler enters the names for the Point structure and slope() function into the global namespace. Suppose a separate geometry.C module contains the slope() implementation and defines origin, a global variable.

Namespace Extensions:

Namespaces are extensible; that is, you can append subsequent declarations to previously defined namespaces. Namespace extensions may also appear in files separate from the original namespace definition. The following two definitions of namespace Blue are equivalent to the definition of namespace BigBlue.

 Write a simple program that has 3 variables named x that are each in separate namespaces.Solution2. Write a simple program that has 3 variables named x that ar

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site