新发现一奇怪语法,求科普!
本帖最后由 zhouxicai 于 2013-06-26 15:38:13 编辑
virtual void SendBuf(const char *,size_t,int = 0);
void SendBuf(const char *buf,size_t len,int f = 0);
C++ socket
void TcpSocket::SendBuf(const char *buf,size_t len,int)
{
if (!Ready() && !Connecting())
{
Handler().LogError(this, "SendBuf", -1, "Attempt to write to a non-ready socket" ); // warning
if (GetSocket() == INVALID_SOCKET)
Handler().LogError(this, "SendBuf", 0, " * GetSocket() == INVALID_SOCKET", LOG_LEVEL_INFO);
if (Connecting())
Handler().LogError(this, "SendBuf", 0, " * Connecting()", LOG_LEVEL_INFO);
if (CloseAndDelete())
Handler().LogError(this, "SendBuf", 0, " * CloseAndDelete()", LOG_LEVEL_INFO);
return;
}
if (!IsConnected())
{
Handler().LogError(this, "SendBuf", -1, "Attempt to write to a non-connected socket, will be sent on connect" ); // warning
Buffer(buf, len);
return;
}
if (m_obuf_top)
{
Buffer(buf, len);
return;
}
int n = TryWrite(buf, len);
if (n >= 0 && n < (int)len)
{
Buffer(buf + n, len - n);
}
// if ( data in buffer || !IsConnected )
// {
// add to buffer
// }
// else
// try_send
// if any data is unsent, buffer it and set m_wfds
// check output buffer set, set/reset m_wfds accordingly
{
bool br;
bool bw;
bool bx;
Handler().Get(GetSocket(), br, bw, bx);
if (m_obuf.size())
Set(br, true);
else
Set(br, false);
}
}
[解决办法]
默认值的意思吧.
[解决办法]
默认参数啊,很常见的
[解决办法]
在函数声明中,实际上只需要给出各参数的数据类型,不需要写出参数的变量名——因为这个变量名根本用不到
不过在实际中一般都是要写的,因为这样可以更容易理解该函数各参数的用途
所以这里的int = 0和int a = 0是一个意思,当然这种写法也就只在函数声明中合理