Get ptr function for member function of instanced class?

class gfx { 
    void resize(int x, int y);
}

gfx g;    

Can I g.resize to "void (*) (int, int)" in some way?

+3
source share
2 answers

No. gfx::resizehas type void(gfx::*)(int, int). You cannot convert it to text void(*)(int, int)because it can only be called as a member function for an object of type gfx.

- , , gfx g;, g.resize(), resize(), . -, .

- , this, , .

- , nonmember ( -) , , -. , :

void resize(gfx* obj, int x, int y) {
    return obj->resize(x, y);
}

nonmember resize void(*)(gfx*, int, int) nonmember. - std::function std::bind, ++ 0x ( Boost ++ TR1).

+6

, :

void easy_resize(int x, int y) { g.resize(x, y); }
0

Source: https://habr.com/ru/post/1782374/


All Articles