への変換演算子を持つクラスがありstd::stringます。std::basic_string<T>関数の受信(テンプレート化)を除いて、すべてでうまく機能しますT。
#include <string>
struct A{
operator std::string(){return std::string();}
};
void F(const std::basic_string<char> &){}
template<typename T> void G(const std::basic_string<T> &) {}
int main(){
A a;
F(a); // Works!
G(a); // Error!
return 0; // because otherwise I'll get a lot of comments :)
}
私が受け取るエラーは
error: no matching function for call to 'G(A&)'
note: candidate is:
note: template<class T> void G(const std::basic_string<_CharT>&)
Gこれで、構造体でフレンドとして定義できA、それが機能することはわかっていますが、私の問題は、既に存在して受け取っている多くの stl 関数std::basic_string<T>(たとえば、operator<<印刷関数、比較演算子、または他の多くの関数) にあります。 .
Aのように使えるようになりたいstd::stringです。これを行う方法はありますか?