我有一个派生的basic_ostream类和一个内联修饰符(类似于setw)。我的流类还应该从其父类继承所有运算符#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 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 而是从std::basic_ostream继承,仅使用常规流为修饰符结构重新实现std::ostream & operator << (std::ostream &stream, const modifier & mod){ // ...custom behavior... return stream;}您的解决方案似乎过于复杂,但是我认为您得到的实际错误是由 (adsbygoogle = window.adsbygoogle || []).push({});
07-24 19:08
查看更多