samples/main-component-manager.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 02 Jan 2008 09:09:24 +0100
changeset 2230 9f13ac3291e0
parent 727 3bcec84f9f54
permissions -rw-r--r--
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.

#include "ns3/object.h"
#include "ns3/component-manager.h"

using namespace ns3;

class AnObject : public Object
{
public:
  static const InterfaceId iid;
  static const ClassId cid;
  AnObject (int a, double b);
protected:
  virtual void DoDispose (void);
};

const InterfaceId AnObject::iid = MakeInterfaceId ("AnObject", Object::iid);
const ClassId AnObject::cid = MakeClassId<AnObject, int, double> ("AnObject", AnObject::iid);

AnObject::AnObject (int a, double b)
{}
void
AnObject::DoDispose (void)
{
  // Do your work here.
  // chain up
  Object::DoDispose ();
}


int main (int argc, char *argv[])
{
  Ptr<AnObject> anObject = ComponentManager::Create<AnObject,int,double> (AnObject::cid, AnObject::iid, 10, 20.0);
  NS_ASSERT (anObject != 0);
  return 0;
}