// ---------------------------------------------------------------------- // // tmplfrnd.cc - Do we support templated friends? // // History: // 21-Sep-1999 WEB Initial draft, adapted from SGIport // 25-Apr-2001 WEB s//"ISOcxx\/ISOcxxSyntax.hh"/ // // ---------------------------------------------------------------------- #include "ISOcxx/ISOcxxSyntax.hh" // ---------------------------------------------------------------------- // forward-declare the friend-to-be: // ---------------------------------------------------------------------- template< class T > struct F; // ---------------------------------------------------------------------- // define C, granting friendship to all F<> specializations: // ---------------------------------------------------------------------- template< class T > class C { public: C() : myT( T() ) { ; } // constructor using T's default value #if ! defined DEFECT_NO_FRIEND_TEMPLATES private: template< class U > friend struct F; #endif T myT; }; // C // ---------------------------------------------------------------------- // define F whose member f() requires friendship of C: // ---------------------------------------------------------------------- template< class T > struct F { T f( C const & c ) const { return c.myT; } }; // F // ---------------------------------------------------------------------- // test driver: // ---------------------------------------------------------------------- int main() { C ci; F fi; return fi.f( ci ); } // main()