C++相談室 part50
■ このスレッドは過去ログ倉庫に格納されています
0265243
2006/06/15(木) 06:33:38前方宣言も必要ないし。
多少面倒でも、>>244のようにすべきなのでしょうか。
template < int X >
class Foo
{
//Barton and Nackman Trick
friend std::ostream & operator << ( std::ostream & out, Foo<X> const & val )
{
val.print(out) ;
return out ;
}
//こっちは厳密に言うとBarton and Nackman Trickじゃないかもしれないけど、よりジェネリックに。
/*********
* template < typename CharType >
* friend std::basic_ostream<CharType> & operator << ( std::basic_ostream<CharType>, Foo<X> const & val) ;
* { val.print(out) ; return out ;}
*************************/
private :
//実際の出力は、このメンバ関数が行う。
void print( std::ostream & out ) const { out << "private!" ; };
} ;
■ このスレッドは過去ログ倉庫に格納されています