【发布时间】:2020-04-27 00:09:37
【问题描述】:
我是新手 C++ 程序员,所以这可能会变得一团糟。
我正在编写一个程序来将二进制 Windows ETL 文件转换为 Wireshark PCAPNG。更准确地说,我正在修复由于 ETL 格式的更改而出现的错误。要修复这个错误,我需要在我的代码中添加一个回调。以下是代码中的相关部分:
#include <iostream>
#include <fstream>
#include <functional>
// Ng Block Buffer
typedef struct _NG_BLK_BUFFER {
int blockType = 0;
// ...
} NG_BLK_BUFFER;
class RingBuffer
{
public:
// ...
std::function<void(NG_BLK_BUFFER*)> framePayloadWriter;
};
class PcapNgFile : public std::ofstream
{
public:
// ...
PcapNgFile(const std::wstring fileName, size_t ringBufferSize);
void writeEPB();
// ...
RingBuffer* ringBuffer;
};
PcapNgFile::PcapNgFile(const std::wstring fileName, size_t ringBufferSize)
{
// ...
this->ringBuffer = new RingBuffer();
this->ringBuffer->framePayloadWriter = std::bind(&PcapNgFile::writeEPB, this, std::placeholders::_1);
}
void PcapNgFile::writeEPB()
{
std::cout << "Writing an EPB" << std::endl;
}
int wmain(int argc, wchar_t** argv)
{
PcapNgFile* myPcapNg = new PcapNgFile(L"test.pcap", 1);
}
对于第 36 行,我收到错误:
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::_Binder<std::_Unforced,void (__thiscall PcapNgFile::* )(void),PcapNgFile *,const std::_Ph<1> &>' (or there is no acceptable conversion)
第 36 行是:
this->ringBuffer->framePayloadWriter = std::bind(&PcapNgFile::writeEPB, this, std::placeholders::_1);
我做错了什么?
【问题讨论】:
标签: c++ functional-programming bind