这样多点是什么用法
这么多点是什么用法?
是多个函数调用么?
------解决方案--------------------
AddAttribute 返回了对象自身的引用吧,这样就可以无限点下去的,等价于
static TypeId tid = TypeId ("ns3::Node");
...
tid.AddAttribute( ... );
tid.AddAttribute( ... );
tid.AddAttribute( ... );
tid.AddAttribute( ... );
...
------解决方案--------------------
上一个函数返回一个类型,再通过 .号执行它的成员函数
------解决方案--------------------
C++
这个点,不过是对象调用方法的语法。
C++,Java 都可以这样用
这里,每个点前面的函数,都是返回类类型或者类的引用类型的函数(方法)
返回值是对象,或者对象的引用。
所以可以这样写。
类似的例子,如 cin>>a>>b>>c;
可以写成 cin.operator>>(a)
.operator>>(b)
.operator>>(c);
TypeId
Node::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Node")
.SetParent<Object> ()
.AddConstructor<Node> ()
.AddAttribute ("DeviceList", "The list of devices associated to this Node.",
ObjectVectorValue (),
MakeObjectVectorAccessor (&Node::m_devices),
MakeObjectVectorChecker<NetDevice> ())
.AddAttribute ("ApplicationList", "The list of applications associated to this Node.",
ObjectVectorValue (),
MakeObjectVectorAccessor (&Node::m_applications),
MakeObjectVectorChecker<Application> ())
.AddAttribute ("Id", "The id (unique integer) of this Node.",
TypeId::ATTR_GET, // allow only getting it.
UintegerValue (0),
MakeUintegerAccessor (&Node::m_id),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("SystemId", "The systemId of this node: a unique integer used for parallel simulations.",
TypeId::ATTR_GET|TypeId::ATTR_SET,
UintegerValue (0),
MakeUintegerAccessor (&Node::m_sid),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
是多个函数调用么?
------解决方案--------------------
AddAttribute 返回了对象自身的引用吧,这样就可以无限点下去的,等价于
static TypeId tid = TypeId ("ns3::Node");
...
tid.AddAttribute( ... );
tid.AddAttribute( ... );
tid.AddAttribute( ... );
tid.AddAttribute( ... );
...
------解决方案--------------------
上一个函数返回一个类型,再通过 .号执行它的成员函数
------解决方案--------------------
C++
这个点,不过是对象调用方法的语法。
C++,Java 都可以这样用
这里,每个点前面的函数,都是返回类类型或者类的引用类型的函数(方法)
返回值是对象,或者对象的引用。
所以可以这样写。
类似的例子,如 cin>>a>>b>>c;
可以写成 cin.operator>>(a)
.operator>>(b)
.operator>>(c);