mercredi 10 juillet 2019

Why can I store a callable target in a std::function which dosen't match the type

I have tried the following:

typedef std::function<void(int)> callback;

struct testclass
{
    void testfunc()
    {
        printf("test\n");
    }
};

int main()
{
    testclass test;
    callback c = std::bind(&testclass::testfunc, &test);
    c(1);
}

The output is

test

The std::bind returns a callable target like void(void), while the callback should be stored a void(int).

Why can I do this?

Aucun commentaire:

Enregistrer un commentaire