In g(), to what does the call, f(‘a’) resolve? How could the code be modified so that the call still resolves to A::f(int)?

Suppose we have the following namespace:
```
namespace A
{
void f(int);
//. . .
}
using namespace A;

// In the global namespace
void g()
{
f(‘a’); // calls A::f(int)
}
```

In the global namespace, the function g( ) calls f(‘a’). There is no problem here, f(‘a’) is unambiguously A::f(int). Now suppose at some later time, the following namespace grouping and using directive is inserted prior to the call to function f.
```
namespace B
{
void f(char);
//. . .
}
using namespace B;
```

For convenience, all these are listed again.
namespace A
```
{
void f(int);
//. . .
}
using namespace A;

namespace B
{
void f(char);
//. . .
}
using namespace B;
// In the global namespace
void g()
{
f(‘a’);
}
```


The call, f(‘a’) resolves to B::f. The using namespace directives make both A::f(int) and B::f(char) are available, and so the resolution is made by exact match.
Modified code that cause A::f(int) to be called in g() follows:
```
#include
using std::cout;
namespace A
{
void f(int);
//. . .
}
void A::f(int) { cout << "A::f(int)\n"; }

using namespace A;
//using A::f;
namespace B
{
void f(char);
//. . .
}
void B::f(char) { cout << "B::f(char)\n"; }
using namespace B;
//using B::f; // We could write this instead
// In the global namespace
void g()
{
cout << "::g() \n";
A::f('a'); // forces f(int)
B::f('a'); // forces f(char)
}
int main()
{
g();
}
```

Computer Science & Information Technology

You might also like to view...

Use find with the –size (Sobell, page 830) criterion to list the names of files in your home directory that are smaller than 100 bytes.

What will be an ideal response?

Computer Science & Information Technology

FirstName, LastName, StreetAddress, and City are examples of record names

Indicate whether the statement is true or false

Computer Science & Information Technology

What is one important limitation of the Simple Query Wizard?

What will be an ideal response?

Computer Science & Information Technology

A ________ is a partially completed document that contains preformatted text and/or graphics

A) template B) Quick Part Galley C) placeholder D) Building Block

Computer Science & Information Technology