vendredi 11 août 2017

std::function - conversion from '

I am playing around with a simple std::function example and I am getting the error

main.cpp: In member function 'void test::foo()':
main.cpp:15:38: error: conversion from '<unresolved overloaded function type>' to non-scalar type 'std::function<void(int)>' requested
         std::function<void(int)> b = std::bind<&test::bar,this,1>;
                                      ^~~

This is my code

class test 
{
    public:
    void bar(int a) {
        std::cout << "Value is " << a;
    }

    void foo() {
        std::function<void(int)> b = std::bind<&test::bar,this,1>;
        b();
    }
};

The function foo simply calls bar using std::function Any suggestions on why I am getting this error.

Aucun commentaire:

Enregistrer un commentaire