为什么我的类的强制转换操作符不能用于std :: string?

时间:2014-11-20 14:51:47

标签: c++ operators

我有以下课程:

template<typename T>
class Foo
{
public:
    typedef T value_type;
    operator value_type const& () const { return _val; }

private:
    value_type _val;
}

当T为float,int等时,它与std::ostream一起使用。 但是对于std::string我必须这样做:

std::cout << f.operator const std::string &();

所以我的问题是为什么?我可以为std::cout << f Foo<int>而不是Foo<std::string>

0 个答案:

没有答案