错误 C2663:指针'this'重载没有合法转换



请帮我解决的这个错误

代码:

u16 ip_defragment(){
    u16 result;
    fragip_set::iterator i;
    IP_FRAGMENTED new_defrag;
    IP* pcurpack = (IP*) malloc(cur.len);
    memcpy(pcurpack, cur.data, cur.len);
    new_defrag.saddr = cur.saddr;
    new_defrag.daddr = cur.daddr;
    new_defrag.protocol = cur.ip.ppack->protocol;
    new_defrag.id = i2i(cur.ip.ppack->id);
    i = ip_frags.find(new_defrag);
    if(i != ip_frags.end()){
            i->packets.insert(pcurpack);
            const_cast<u16&>(i->cur_len) += cur.ip.len - cur.ip.hlen; 
            const_cast<u32&>(i->last_time) = time();
            if(!(cur.ip.bmore_fr) && (i->tot_len == 0)){
            const_cast<u16&>(i->tot_len) = cur.ip.fr_offs + cur.ip.len;
            }
            if(i->cur_len == i->tot_len){
                for(set<IP*>::iterator k = i->packets.begin(); k != i->packets.end(); k++){
                    // must copy to another buffer
                    if(i2i((*k)->frag_off) & IP_OFFMASK){
                        memcpy(ip_defrag_buffer, *k, (*k)->ihl<<2);
                    } else {
                        memcpy(ip_defrag_buffer + (i2i((*k)->frag_off) & IP_OFFMASK) * 8, 
                            *k + ((*k)->ihl<<2), (i2i((*k)->tot_len))-((*k)->ihl<<2));
                    }
                }
                IP* defr_ip = (IP*) &ip_defrag_buffer;
                defr_ip->tot_len = i2i(i->tot_len);
                defr_ip->frag_off = 0;
                result = i->tot_len;
                ip_frags.erase(i);
                return result;
            }
            return 0;
    }

    if(!(cur.ip.bmore_fr)){
        new_defrag.tot_len = cur.ip.fr_offs + cur.len;
    } else {
        new_defrag.tot_len = 0;
    }
    new_defrag.cur_len = cur.ip.len; // with header size
    new_defrag.last_time = time();
    i = ip_frags.insert(new_defrag).first;
    if(i != ip_frags.end())
        i->packets.insert(pcurpack);
    return 0;
}

编译项目,只查看2个类似的错误

第15行:i->packets.insert(pcurpack);

端线:i->packets.insert(pcurpack);

错误,有2行:错误C2663:"std::_Tree&lt_特征>::insert':4个重载对"this"指针没有合法转换

IntelliSense: no instance of overloaded function "std::set<_Kty, _Pr, _Alloc>::insert [with _Kty=IP *, _Pr=std::less<IP *>, _Alloc=std::allocator<IP *>]" matches the argument list and object (the object has type qualifiers that prevent a match)

请帮帮我?

我在将std::set传递给lambda表达式时遇到了完全相同的错误:

C2663 'std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::insert': 5 overloads have no legal conversion for 'this' pointer

lambda表达式原型是:

[se1, ele1](auto val) {
    /* here I was editing se1 set, but above se1 is passed value type */
}

我已更改为:

[&se1, ele1](auto val) {
    /* now since se1 set is sent as reference type above, it is good to edit
       changes stays as I expect it to be
    */
}

现在编译成功。

我使用了count_if函数,它为eac元素调用lamda表达式,所以编译器知道修改应该在集合se1中持续存在,这是完全合乎逻辑的。

如果您希望原始集保持不变,则发送一份副本。

最新更新