一個經常使用的創建對象的方法是:調用CreateObject(),在ns3中,也可以使用ObjectFactory類。在helper類中經常使用。
ObjectFactory類可以實例化對象,也可以設置屬性,例如:
void SetTypeId (TypeId tid);
void Set (std::string name, const AttributeValue &value);
Ptr<T> Create (void) const;
第一個方法:創建對象。
第二個方法:設置屬性。
第三個方法:創建對象本身。
例如:
ObjectFactory factory;
// Make this factory create objects of type FriisPropagationLossModel
factory.SetTypeId ("ns3::FriisPropagationLossModel")
// Make this factory object change a default value of an attribute, for
// subsequently created objects
factory.Set ("SystemLoss", DoubleValue (2.0));
// Create one such object
Ptr<Object> object = factory.Create ();
factory.Set ("SystemLoss", DoubleValue (3.0));
// Create another object with a different SystemLoss
Ptr<Object> object = factory.Create ();
這個類常用的public函數: