派生 basic_ostream クラスとインライン修飾子 (setw に似ています) があります。私のストリーム クラスは、すべての演算子 << 動作も親から継承する必要があります。「using」キーワードを使用するかどうかに応じて、さまざまなコンパイラ エラーが発生します。
#include <iostream>
struct modifier { };
template <typename C, typename T=std::char_traits<C> >
struct mystream : public std::basic_ostream<C, T>
{
// this is where the trouble is
using std::basic_ostream<C, T>::operator <<;
inline mystream & operator << (const modifier & mod)
{
// ...custom behavior...
return *this;
}
};
int main()
{
mystream<char> foo;
modifier m;
foo << "string"; // this fails if the using is present
foo << 123; // this fails if the using is absent
foo << m;
}
using ディレクティブを入れると、コンパイラは「文字列」出力について混乱し、それをコメントアウトすると、整数 123 出力について混乱し、どちらの場合も「エラー: 'operator<< のあいまいなオーバーロード」が表示されます。 」。g++ 4.2.1 と g++4.8 の両方に問題があります。ここで進むべき正しい道は何ですか?