//: C05:FriendScope2.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. #include using namespace std; // Necessary forward declarations: template class Friendly; template void f(const Friendly&); template class Friendly { T t; public: Friendly(const T& theT) : t(theT) {} friend void f<>(const Friendly&); void g() { f(*this); } }; void h() { f(Friendly(1)); } template void f(const Friendly& fo) { cout << fo.t << endl; } int main() { h(); Friendly(2).g(); } ///:~