首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类中的c++函数调用与定义不匹配

类中的c++函数调用与定义不匹配
EN

Stack Overflow用户
提问于 2018-01-22 15:59:50
回答 1查看 107关注 0票数 0

我正在阅读下面的C++代码:

代码语言:javascript
复制
// 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正在搜索的标志。

EN

回答 1

Stack Overflow用户

发布于 2018-01-22 16:02:22

参数不一定需要通过,因为它默认为T::pdu_flag

调用站点上的<TCP>符号消除了模板的歧义(这是必需的,因为由于没有任何函数参数,所以不能从任何函数参数中收集适当的模板实例化)。默认的参数值将是TCP::pdu_flag,不管它是什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48385629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档