以下のサンプルコードでは、boost::tupleが最初のテンプレート引数から暗黙的に作成できることを示しています。<<
そのため、あいまいになるため、演算子を記述できません。
ostringstream& << float
また、なぜあいまいなのかもわかりません。これには暗黙の構造はありません。なぜこれもあいまいなエラーを出すのですか?
#include <iostream>
#include <boost/tuple/tuple.hpp>
#include <sstream>
#include <string>
using namespace std;
class Myclass
{
};
typedef boost::tuple<int,float,Myclass> Mytuple;
ostringstream& operator<<(ostringstream& os_, Mytuple tuple_)
{
float f = tuple_.get<1>();
//os_ << (int)tuple_.get<0>(); // Error because int is implicitly converted into Mytuple. WHYY?
//os_ << tuple_.get<1>(); // No Clue Why this is ambiguous.
//os_ << tuple_.get<2>(); // Error because no matching operator. Fine.
return os_;
}
int main()
{
Mytuple t1;
t1 = 3; // Working because int is implicitly converted into Mytuple!! WHY?
//t1 = 3.0f; // Error because no matching constructor. Fine.
return 0;
}
エラーメッセージ:
tupleTest2.C:18:エラー:ISO C ++は、最初の変換の最悪の変換が2番目の変換の最悪の変換よりも優れているにもかかわらず、これらはあいまいであると言っています。