Answer the following statements true (T) or false (F)
1. During name resolution, nested namespaces behave like nested blocks.
2. A namespace is just a class with all the folderol stripped off.
3. Namespaces can be defined in pieces across several files.
4. A namespace grouping requires a semicolon after the closing curly brace.
5. The output from the following code is
“function”.
(The code will compile and run.)
```
#include
using namespace std;
namespace
{
char c_string[ 10 ] = "namespace";
}
void output()
{
char c_string[ 10 ] = "function";
cout << c_string << endl; // which c_string?
//other code
}
int main()
{
output();
}
```
1. True
When a name is used in a nested namespace, the surrounding namespace is searched for a declaration.
2. False
It does look like that, but a sort of opposite is closer to the truth. A class is very much like a specialized namespace. All operations supported for namespaces can be applied to classes with the same meaning.
3. True
4. False
A namespace definition is not like a class definition, in which an object of class type can be defined at the class definition. A namespace is not a type, so such a definition is not possible. There is no need for the semicolon. (At least this is not a reason for the semicolon. This writer knows of no other reason for a terminating semicolon for a class-like construct.)
5. True
As far as the local function is concerned, the unnamed namespace is a global definition of an array c_string. (Technically, we say c_string is local to the file, but non-local to the function.) The variable c_string defined in the
You might also like to view...
Refer to the Exhibit. An administrator has created the resource pool configuration shown in the Exhibit. Based on the exhibit, which virtual machine(s) can be successfully powered on?
A. VM-M1 only B. VM-K1 only C. VM-K1 and VM-K2 only D. VM-K1, VM-K2, and VM-M1
Find the error in each of the following program segments. Assume the following declara- tions and statements:
``` int* zPtr; // zPtr will reference built-in array z int number; int z[5]{1, 2, 3, 4, 5}; ``` a) ++zPtr; b) // use pointer to get first value of a built-in array c) // assign built-in array element 2 (the value 3) to number d) // display entire built-in array z e) ++z;