我是 C++ 新手,我在“.h”文件中发现了一些我无法真正理解的与虚拟相关的代码。有一个名为 NetDeviceContainer 的类,在以下类 WifiHelper 中使用。 WifiHelper中的以下两个方法让我困惑:
(1) NetDeviceContainer 虚拟安装 (......) const;
(2)虚拟NetDeviceContainer Install (......)const;
我想我已经弄清楚第一个方法的含义,但是第二个方法(NetDeviceContainer前面的virtual)的含义是什么?它有什么用?
class WifiHelper
{
/**
* \param phy the PHY helper to create PHY objects
* \param mac the MAC helper to create MAC objects
* \param first lower bound on the set of nodes on which a wifi device must be created
* \param last upper bound on the set of nodes on which a wifi device must be created
* \returns a device container which contains all the devices created by this method.
*/
NetDeviceContainer virtual Install(const WifiPhyHelper& phy,
const WifiMacHelper& mac,
NodeContainer::Iterator first,
NodeContainer::Iterator last) const;
/**
* \param phy the PHY helper to create PHY objects
* \param mac the MAC helper to create MAC objects
* \param c the set of nodes on which a wifi device must be created
* \returns a device container which contains all the devices created by this method.
*/
virtual NetDeviceContainer Install(const WifiPhyHelper& phy,
const WifiMacHelper& mac,
NodeContainer c) const;
}
virtual
的顺序和返回类型并不重要。它的两个重载,都返回 NetDeviceContainer
类型的实例。
如果你理解了第一个,那么第二个也应该很难理解。我猜它会做一些类似的事情:
virtual NetDeviceContainer Install(const WifiPhyHelper& phy,
const WifiMacHelper& mac,
NodeContainer c) const {
return Install(phy,mac,c.begin(),c.end());
}
第一个更通用,因为您可以传递一个子范围,而不是只传递整个容器。