Garmaine Staff asked 2 years ago

Simple program to demonstrate the problem:

#include <vector>
#include <functional>
#include <iostream>

//class MyClass
    void initTest (std::vector< std::function<bool()> > funcVec)
        for (auto func : funcVec);

    bool a () { return true; }
    bool b () { return false; }
    bool c () { return false; }

    void test ()
        initTest({a, b, c});

int main ()
    return 0;

As written it compiles with no errors, but if you uncomment the class definition it won't compile at all. The error message claims "no known conversion from brace-enclosed initialiser list to vector of functions", but clearly there is, as outside the class it works just fine.

Can someone explain what the error is and (if posssible) give a solution? Many thanks.