Friday, 9 August 2013

C++ rare method definition

C++ rare method definition

I found a sockets simplified library on internet. In it I came across a
way of defining class method, I never seen it before. Here is the part of
Socket class.
class Socket {
public:
Socket();
virtual ~Socket();
bool create();
private:
int m_sock;
sockaddr_in m_addr;
};
Socket::Socket() :
m_sock(-1) {
memset(&m_addr,
0,
sizeof ( m_addr));
}
I dont understand Socket::Socket() : m_sock(-1){...} syntax. Is m_sock is
being initialized? In the above library, to create a socket Socket object
was never created i.e, Socket() constructor was never called,
Socket::create() method is called statically. Any way what does
Socket::Socket() : m_sock(-1){...} mean?

No comments:

Post a Comment