gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:45:40 28 4
gpt4 key购买 nike

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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com