topic description
in the fun call of the TcpSocket, function derived from the base class socketBase, the this pointer of the derived class is passed to the function that takes the socketBase pointer of the base class as an argument. In the function, the type is converted to TcpSocket, but it is found that all the members in the TcpSocket are set to 0, and the members in the base class are correct.
debug with gdb, but in the debugging tool, the contents of variables in the TcpSocket class in fun are normal, but the contents of the variables printed out by the actual running of the program are 0 for no reason.
the picture is as follows:
gdb debugging:
(gdb) p tcpSocket->m_bConnected
$2 = true
(gdb) p tcpSocket->m_uid
$3 = 12
(gdb) p tcpSocket->m_iLastRecvTime
$4 = 1532751659
Program run print:
TrackerMgr::onClose m_bConnected 0, uid 0, lasttime 0.
idea:
you can basically make sure that there is no problem with type conversion, and you can also see that there is no problem with member variable access in the debugging tool. I really don"t know what the reason is.