D
David Sachs
The following program illustrates an interesting effect of the way C++
resolves function overloading.
I have verified with a member of the C++ stardard committee that the output
shown is correct.
*********************************Program********************************
#include <iostream>
using std::cout;
using std::endl;
namespace test
{
enum test1 { testa=3, testb=4 };
std:stream& operator<<(std:stream& os, test::test1 t)
{
os << " **** TEST1 **** ";
return os;
}
enum test2 { testc = 5, testd = 7 };
}
std:stream& operator<<(std:stream& os, test::test2 t)
{
os << " **** TEST2 **** ";
return os;
}
test::test1 i(test::testa);
test::test2 j(test::testc);
namespace test
{
void testy()
{
cout << i << endl;
cout << j << endl;
}
}
int main()
{
cout << "Direct\n";
cout << i << endl;
cout << j << endl;
cout << "Indirect\n";
test::testy();
return 0;
}
********************************Output********************************
Direct
**** TEST1 ****
**** TEST2 ****
Indirect
**** TEST1 ****
5
resolves function overloading.
I have verified with a member of the C++ stardard committee that the output
shown is correct.
*********************************Program********************************
#include <iostream>
using std::cout;
using std::endl;
namespace test
{
enum test1 { testa=3, testb=4 };
std:stream& operator<<(std:stream& os, test::test1 t)
{
os << " **** TEST1 **** ";
return os;
}
enum test2 { testc = 5, testd = 7 };
}
std:stream& operator<<(std:stream& os, test::test2 t)
{
os << " **** TEST2 **** ";
return os;
}
test::test1 i(test::testa);
test::test2 j(test::testc);
namespace test
{
void testy()
{
cout << i << endl;
cout << j << endl;
}
}
int main()
{
cout << "Direct\n";
cout << i << endl;
cout << j << endl;
cout << "Indirect\n";
test::testy();
return 0;
}
********************************Output********************************
Direct
**** TEST1 ****
**** TEST2 ****
Indirect
**** TEST1 ****
5