i'm trying to understand a concept and an error. what's wrong with this?
class A
{
public:
A()
{
std::function<void(int)> testFunc(&A::func);
}
private:
void func(int) {}
}
my question, is it possible to create any sort of object that is able to call a member of a specific instance where std::function acts like a member function pointer, except without the wacky type definition that can't be used as function parameters in inheriting classes. for example:
class A
{
public:
A()
{
index[WM_CREATE] = &A::close;
index[WM_DESTROY] = &A::destroy;
}
protected:
map<UINT msg, void (A::*)(HWND, UINT , WPARAM, LPARAM)> index;
void close(HWND,UINT, WPARAM, LPARAM);
void destroy(HWND, UINT, WPARAM, LPARAM);
};
class B : public A
{
public:
B()
{
index[WM_CREATE] = &B::create; // error because it's not a pointer of type A::*
}
private:
void create(HWND, UINT, WPARAM, LPARAM);
};
I'm thinking i'm on the right track of using std::functions like so:
class A
{
public: // Gigantic stl error with these two
A() // |
{ // V
index[WM_CREATE] = std::function<void(HWND, UINT, WPARAM, LPARAM>(&A::close);
index[WM_DESTROY] = std::function<void(HWND, UINT, WPARAM, LPARAM>(&A::destroy);
}
protected:
map<UINT msg, std::function<void(HWND, UINT, WPARAM, LPARAM)> > index;
void close(HWND,UINT, WPARAM, LPARAM);
void destroy(HWND, UINT, WPARAM, LPARAM);
};
class B : public A
{
public: // and this one
B() // |
{ // V
index[WM_CREATE] = std::function<void(HWND, UINT, WPARAM, LPARAM)>(&B::create);
}
private:
void create(HWND, UINT, WPARAM, LPARAM);
};
if someone could explain what these giant cryptic errors mean and how to fix them, i would greatly appreciate it.
See Question&Answers more detail:os