c++ - 从 std::streambuf 继承时出现不兼容的析构函数编译器警告

标签 c++ iostream icc streambuf

std::streambuf 继承时,我收到 ICL 编译器警告,指出析构函数不兼容,您知道我在这里做错了什么吗?使其成为虚拟析构函数也不起作用。

warning #809: exception specification for virtual function "CAbcBuffer::~CAbcBuffer" is incompatible with that of overridden function "std::basic_streambuf<_Elem, _Traits>::~basic_streambuf [with _Elem=char, _Traits=std::char_traits]"

class CAbcBuffer : public std::streambuf
{
    protected:
        /** Work buffer */
        char *buffer;
    public:
        explicit CAbcBuffer()
        {
            /*
            Stores the beginning pointer, the next pointer, and the end pointer for the 
            input buffer
            */
            buffer = new char[100];
            std::streambuf::setg(buffer, buffer, buffer);
        }

        ~CAbcBuffer() {
            delete [] buffer;
        }
}

最佳答案

您缺少析构函数的 throw() 声明。这将解决问题:

~CAbcBuffer() throw() {
    delete [] buffer;
}

关于c++ - 从 std::streambuf 继承时出现不兼容的析构函数编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22119173/

相关文章:

c++ - 如何检测和处理算法中不受支持的语言环境?

c++ - 继承显式构造函数 (Intel C++)

c++ - boost 从结构列表派生的结构的序列化

c++ - .txt 到 vector<struct> 故障

Android 客户端终止连接

C++:用户输入产生不需要的行为

c++ - gcc 和 intel 在 redhat 上的 icpc 不识别命名空间 std::literals;

c++ - 结合大型 C 和 C++ 程序

c++ - C 和 C++(也可能是 Objective-C)中的 Lint 工具

c++ - 重写虚方法时无法返回派生类指针