我正在阅读下面的C++代码:
// Take a whole packet from somewhere.
EthernetII packet = ...;
// Find the IP layer
const IP* ip = packet.find_pdu<IP>();
if(ip) {
// If the pointer is not null, then it will point to the IP layer
}
// Find the TCP layer. This will throw a pdu_not_found exception
// if there is no TCP layer in this packet.
const TCP& tcp = packet.rfind_pdu<TCP>();PDU::rfind_pdu()的定义如下。我的问题是,一个论点不应该传递给rfind_pdu()吗?允许<IP>附加到函数调用的语法是什么?
template<typename T> const T& Tins::PDU::rfind_pdu(PDUType type = T::pdu_flag) const inline查找并返回与给定标志匹配的第一个PDU。 参数flag正在搜索的标志。
发布于 2018-01-22 16:02:22
参数不一定需要通过,因为它默认为T::pdu_flag。
调用站点上的<TCP>符号消除了模板的歧义(这是必需的,因为由于没有任何函数参数,所以不能从任何函数参数中收集适当的模板实例化)。默认的参数值将是TCP::pdu_flag,不管它是什么。
https://stackoverflow.com/questions/48385629
复制相似问题