• Advertisement

Archived

This topic is now archived and is closed to further replies.

custom types in loop statements

This topic is 5810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

for some reason i cant compare two sockaddr_in structs in a loop statement. my code looks a bit like this: if (addr1.sin_addr == addr2.sin_addr) // do some code here when i try compiling it, it gives me 13 main.cpp no match for `in_addr & == in_addr &'' how would i go about solving this problem?

Share this post


Link to post
Share on other sites
Advertisement
You are actually trying to compare two objects of type in_addr. You need to compare each individual element of the struct, preferably by creating a function that performs the comparison. Since you are using C++, you can create an operator==() which does this for you.

It would look like this:

  
bool operator==( const in_addr& lhs, const in_addr& rhs )
{
// do comparison

if(they_are_the_same)
return true
else
return false;
}


Your compiler is complaining about the fact you are trying to use such an operator when one doesn''t exist.

--

The placement of a donkey''s eyes in its head enables it to see all four feet at all times.

Share this post


Link to post
Share on other sites

  • Advertisement