我的所有类都实现了一个dump成员函数,例如:
struct A {
template <typename charT>
std::basic_ostream<charT> &
dump(std::basic_ostream<charT> &o) const {
return (o << x);
}
int x = 5;
};
Run Code Online (Sandbox Code Playgroud)
我想operator<<为所有这样的类实现一次函数:
template<typename charT, typename T>
std::basic_ostream<charT> &
operator<< (std::basic_ostream<charT> &o, const T &t) {
return t.dump(o);
}
Run Code Online (Sandbox Code Playgroud)
问题是此模板捕获了所有类型,包括标准类型.有办法解决这个问题吗?
c++ ×1