考虑代码:
#include <functional>
#include <vector>
#include <stdint.h>
class CFileOperationWatcher
{
public:
CFileOperationWatcher() {}
virtual void onProgressChanged(uint64_t sizeProcessed, uint64_t totalSize, size_t numFilesProcessed, size_t totalNumFiles, uint64_t currentFileSizeProcessed, uint64_t currentFileSize) {}
virtual ~CFileOperationWatcher() {}
void onProgressChangedCallback(uint64_t sizeProcessed, uint64_t totalSize, size_t numFilesProcessed, size_t totalNumFiles, uint64_t currentFileSizeProcessed, uint64_t currentFileSize) {
_callbacks.emplace_back(std::bind(&CFileOperationWatcher::onProgressChanged, this, sizeProcessed, totalSize, numFilesProcessed, totalNumFiles, currentFileSizeProcessed, currentFileSize));
}
protected:
std::vector<std::function<void ()> > _callbacks;
};
int main(int argc, char *argv[])
{
CFileOperationWatcher w;
w.onProgressChangedCallback(0,0,0,0,0,0);
}
我在 Visual Studio 2012 中收到错误 C2780。看起来没有std::bind
可以接受这么多参数的定义。但是它不应该使用可变参数模板并接受任意数量的参数吗?