Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Can';在多重映射中不插入_C++_Dictionary - Fatal编程技术网

C++ Can';在多重映射中不插入

C++ Can';在多重映射中不插入,c++,dictionary,C++,Dictionary,类的一部分,具有多映射和his参数 class cl_base { string object_name; cl_base* p_parent = 0; struct o_sh { cl_base* p_cl_base; void (cl_base::*p_hendler) (cl_base* p_ob, string&); }; multimap<void(cl_base::*) (string&

类的一部分,具有
多映射
和his参数

class cl_base
{
    string object_name;
    cl_base* p_parent = 0;

    struct o_sh {
        cl_base* p_cl_base;
        void (cl_base::*p_hendler) (cl_base* p_ob, string&);
    };

    multimap<void(cl_base::*) (string&), o_sh*> connects;
    multimap<void(cl_base::*) (string&), o_sh*>::iterator it_connects;

/usr/include/c++/7/bits/stl_function.h:386:20:错误:无效操作数类型为'void(cl_base::*const)(std::_cx11::basic_string&')和'void(cl_base::*const)(std:_cx11::basic_string&')到二进制运算符比较两个指向成员函数的指针比最初出现时更难。它们通常比普通指针大,并且(例如)不能转换为
长的

这里有一个自定义比较器,应该可以工作。我不得不质疑这样做的有效性(也许有一些隐藏的陷阱),但我想如果你需要它,你就需要它

class cl_base;

struct Compare
{
    bool operator () (void (cl_base::*lhs) (string &), void (cl_base::*rhs) (string &)) const
    {
        const int pm_size = sizeof (void (cl_base::*) (string &));
        struct
        {
            unsigned char buf [pm_size];
        } s_lhs, s_rhs;

        memcpy (&s_lhs, &lhs, sizeof (s_lhs));
        memcpy (&s_rhs, &rhs, sizeof (s_rhs));

        for (int i = 0; i < pm_size; ++i)
        {
            if (s_lhs.buf [i] < s_rhs.buf [i])
                return true;
        }

        return false;
    }
};

指向成员的指针只支持运算符
=
=,而不是“handler”中的“hendler”?很难看出这段代码的预期功能是什么,尤其是当你没有演示如何使用它时。你能用代码代替文字来演示吗?最好是有一个简单的答案。我想知道为什么这件事这么复杂。这可能是毫无意义的,也可能是必要的,而这正是一些自包含的演示代码帮助很大的地方。非常感谢你,伙计!!!!!!!!!!
class cl_base;

struct Compare
{
    bool operator () (void (cl_base::*lhs) (string &), void (cl_base::*rhs) (string &)) const
    {
        const int pm_size = sizeof (void (cl_base::*) (string &));
        struct
        {
            unsigned char buf [pm_size];
        } s_lhs, s_rhs;

        memcpy (&s_lhs, &lhs, sizeof (s_lhs));
        memcpy (&s_rhs, &rhs, sizeof (s_rhs));

        for (int i = 0; i < pm_size; ++i)
        {
            if (s_lhs.buf [i] < s_rhs.buf [i])
                return true;
        }

        return false;
    }
};
multimap<void(cl_base::*) (string&), o_sh*, Compare> connects;