[This is the last installment of a column that was being published in C++ Report magazine. Since the magazine ceased publication before this installment could be published, Rob Murray was gracious enough to let us publish it on the CUJ website. The answer to this month's puzzler will appear in a subsequent posting on this website. mb]
Last Month's Puzzle
Last month we asked you to predict the output of the following program:
#include <iostream> using namespace std; namespace N { void g(int) { cout << "g(int)\n"; } }; using namespace N; namespace N { void g(char){ cout << "g(char)\n"; } }; int main(){ g('x'); return 0; }This program prints g(char). The answer hinges on whether the declaration of g(char) is in scope at the point of call. It is, because the "using namespace N" using-directive brings in all declarations in namespace N visible at the point of call -- not just those visible at the point the using-directive appears (as long as the call occurs after the using-directive). This means that the declaration of g(char) is in scope at the call of g('x'). Since g(char) is a better match than g(int), g(char) is called.
This Month's Puzzle
What, if anything, is printed by the following program?
#include <iostream> using namespace std; struct C; struct D { void operator*(D) { cout << "one\n"; } } C; struct E { void operator*(E) { cout << "two\n"; } } F; struct F; int main(){ C* C; F* F; return 0; }As Red Sky's Chief Technology Officer, Rob Murray is responsible for tracking and evaluating current and new Internet technologies. These technologies provide the "plumbing" that is critical to Web-based solutions that are full-featured, robust and fast. "Focus is key," he says. "New tools appear on the market every day. We identify and adopt those technologies that are the very best match for our skills and our customers' needs. Most don't make the cut." Before stepping into the CTO role, Mr. Murray was the Director of Systems Development for the Irvine office of Nuforia, where he was responsible for all fulfillment work in that office. An industry veteran, Mr. Murray spent the first 14 years of his career at AT&T Bell Laboratories, where he worked on object-oriented software and tools, including the first publicly released C++ compiler. He was the founding editor of the C++ Report in 1988, and has been a regular contributor to this respected trade magazine. Mr. Murray has been a prepublication reviewer for many technical textbooks, including important works by C++ inventor Bjarne Stroustrup and Java inventor James Gosling. His own book, C++ Strategies and Tactics (Addison-Wesley 1993), is currently in its seventh printing and has been translated into French and Japanese. His mission statement? "I have to keep three sets of people happy: my customers (who pay the bills); my employees and co-workers (who make successful projects happen); and my bosses (who sign my paycheck). One of the nice things about Red Sky is that if I take care of sets one and two, set three takes care of itself." Mr. Murray has a BS in Computer Science from Michigan State University, and a Master's in Computer Science from the University of Southern California.