edycja wskaźnika na funkcję aby był wskaźnikiem na metodę klasy

0
using FUNC_DOIT  = bool(*)(string &sDll, string &sMessage, WPARAM &wParam, LPARAM &lParam);

Będę przypisywał teraz adresy metod i nie wiem jak przerobić powyższy kod, aby FUNC_DOIT była wskaźnikiem na metodę.
Potrafię to zrobić za pomocą typedef ale kiedyś ktoś powiedział, że bardziej eleganckie używanie using w C++.
Macie jakieś pomysły?
Czy to będzie:

using FUNC_DOIT  = bool(cPLUGIN::*)(string &sDll, string &sMessage, WPARAM &wParam, LPARAM &lParam); 

Jeżeli tak, to dlaczego nie działa mi lambda:

FUNC_DOIT foo = NULL;

    foo = [this](string &sDll, string &sMessage, WPARAM &wParam, LPARAM &lParam)->bool{
        string sM = ">> Call Message: \n";
        sM += "> PluginCreateSucces( "; sM += (const char*)lParam; sM += " )\n";
        f_Console_AddLine(sM);
        return true;
    };
    mDoIt["INFO__PLUGIN_CREATE_SUCCES"] = foo; 

błędy:

=== Build: Release in MainWindow (compiler: GNU GCC Compiler) ===|
In member function 'void cPLUGIN::f_FillMessages()':|
|50|error: cannot convert 'cPLUGIN::f_FillMessages()::__lambda0' to 'FUNC_DOIT {aka bool ()(std::basic_string<char>&, std::basic_string<char>&, unsigned int&, long int&)}' in assignment|
|57|error: cannot convert 'cPLUGIN::f_FillMessages()::__lambda1' to 'std::map<std::basic_string<char>, bool (
)(std::basic_string<char>&, std::basic_string<char>&, unsigned int&, long int&)>::mapped_type {aka bool ()(std::basic_string<char>&, std::basic_string<char>&, unsigned int&, long int&)}' in assignment|
|60|error: cannot convert 'cPLUGIN::f_FillMessages()::__lambda2' to 'std::map<std::basic_string<char>, bool (
)(std::basic_string<char>&, std::basic_string<char>&, unsigned int&, long int&)>::mapped_type {aka bool ()(std::basic_string<char>&, std::basic_string<char>&, unsigned int&, long int&)}' in assignment|
|63|error: cannot convert 'cPLUGIN::f_FillMessages()::__lambda3' to 'std::map<std::basic_string<char>, bool (
)(std::basic_string<char>&, std::basic_string<char>&, unsigned int&, long int&)>::mapped_type {aka bool (*)(std::basic_string<char>&, std::basic_string<char>&, unsigned int&, long int&)}' in assignment|
== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===

3

Zacznij od sprawdzenia czy

sizeof(void(*)()) == sizeof(void(cPLUGIN::*)())

Inaczej mówiąc: tak się nie da.

1

chcesz używać domknięć (lambda clousures)? Używaj std::function

0

@kq - odp. na komentarz:

Kurde to ja nie współgram z programem.
Zmieniłem na:

FUNC_DOIT foo = NULL;
    foo = [](string &sDll, string &sMessage, WPARAM &wParam, LPARAM &lParam, class cPLUGIN *wsk)->bool{
        string sM = ">> Call Message: \n";
        sM += "> PluginCreateSucces( "; sM += (const char*)lParam; sM += " )\n";
        wsk->f_Console_AddLine(sM);
        return true;
    };
    mDoIt["INFO__PLUGIN_CREATE_SUCCES"] = foo; 
using FUNC_DOIT  = bool(*)(string &sDll, string &sMessage, WPARAM &wParam, LPARAM &lParam, class cPLUGIN *wsk); 

(tak jak pisałeś)

auto it = mDoIt.find(sMessage);
    if(it != mDoIt.end())
     return (it->second)(sDll, sMessage, wParam, lParam, this);
    return false; 

i działa mi wszystko ślicznie ! Dzięki Wam chłopaki po raz n-ty!

1 użytkowników online, w tym zalogowanych: 0, gości: 1