2

Consider the code:

#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);
}

I'm getting an error C2780 in Visual Studio 2012. Looks like there's no std::bind definition that can take that many arguments. But isn't it supposed to use variadic templates and accept any number of args?

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335

3 Answers3

2

MSVC++ 2012 has fake variadic templates that rely on macro machinery. By default, they only work for up to 5 parameters. If you need more, you can use _VARIADIC_MAX to up it as high as 10 parameters.

Here's a similar question.

VC++ added variadic templates in the 2013 version.

Community
  • 1
  • 1
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
1

This compiles fine with clang (3.3), so it must be a compiler bug with VS2012. And yes, you're correct: std::bind() is a variadic template (C++11), see also http://en.cppreference.com/w/cpp/utility/functional/bind

Walter
  • 44,150
  • 20
  • 113
  • 196
1

Visual Studio 2012 has no support for variadic templates. Visual Studio 2013 will on the other hand according to this.

dalle
  • 18,057
  • 5
  • 57
  • 81
  • 2
    VC++ 2012 doesn't support true variadic templates, but the run-time library does simulate them for a finite number of arguments using macro machinery. You can adjust the finite number by defining _VARIADIC_MAX. – Adrian McCarthy Aug 16 '13 at 21:47