error C2663: overloads have no legal conversion for 'this' pointer

please help me for this errors

code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
}


compiled project and view only 2 errors similar

line 15 & 51 : i->packets.insert(pcurpack);

error with 2 lines : error C2663: 'std::_Tree<_Traits>::insert' : 4 overloads have no legal conversion for 'this' pointer

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)





Last edited on
Can you show the declaration of fragip_set

this?

1
2
typedef set<IP_FRAGMENTED> fragip_set; // repository for ip fragments
fragip_set ip_frags;
That's not enough for me to determine if:
 
i->packets.insert(pcurpack);
is valid. What is the definition of IP_FRAGMENTED?

definition of IP_FRAGMENTED:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
struct IP_FRAGMENTED
{	
	u32	saddr;		// IvP4 source address
	u32	daddr;		// IvP4 dest address
	u8	protocol;	// protocol 6=tcp 17=udp
	u16 id;			// fragmented packet id
	u16	tot_len;	// total length including Payload
	u16	cur_len;	// total length acquired until now

	u32 last_time;	// last time updated
	set<IP*> packets;// ip fragments from this packet

	bool operator<(const IP_FRAGMENTED& c) const
	{
		COMPARE(saddr, c.saddr)
		COMPARE(daddr, c.daddr)
		COMPARE(id, c.id)
		COMPARE(protocol, c.protocol)
		return false;
	}

};
Your code looks fine as you've presented it to me.

Does that function have all the definitions available to that compiled unit? I mean, do you just have a forward declaration for IP?

I am curious as to why you're using malloc for IP* and not new.
Last edited on
The set iterators are read-only.
Topic archived. No new replies allowed.