Odd error message when trying to cast a structure in C++

Viewed 461

Using C++ on Linux, I just rather stupidly wrote this:

struct in_addr ip_addr = ((struct sockaddr_in)socket_addr).sin_addr;

Instead of the intended:

struct in_addr ip_addr = ((struct sockaddr_in*)&socket_addr)->sin_addr;

Giving me this error:

"error: no matching function for call to ‘sockaddr_in::sockaddr_in(sockaddr&)"

I know why I have the error (I was trying to cast a structure), but I don't understand why the error message says what it does. Can someone please explain?

3 Answers
Related