Violet Giraffe
Violet Giraffe

Reputation: 33579

Code with std::bind not compiling, error C2780: expects 6 arguments - 8 provided

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?

Upvotes: 2

Views: 1302

Answers (3)

Adrian McCarthy
Adrian McCarthy

Reputation: 47952

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.

Upvotes: 2

dalle
dalle

Reputation: 18507

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

Upvotes: 1

Walter
Walter

Reputation: 45424

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

Upvotes: 1

Related Questions