diff --git a/samples/main-object.cc b/samples/main-object.cc index 96b0abd8c..2382fab58 100644 --- a/samples/main-object.cc +++ b/samples/main-object.cc @@ -52,11 +52,40 @@ AnotherObject::DoDispose (void) +class YetAnotherObject : public Object +{ +public: + static const InterfaceId iid; + YetAnotherObject (int a); +private: + virtual void DoDispose (void); +}; + +const InterfaceId YetAnotherObject::iid = MakeInterfaceId ("YetAnotherObject", Object::iid); + +YetAnotherObject::YetAnotherObject (int a) +{ + // enable our interface + SetInterfaceId (YetAnotherObject::iid); + // aggregated directly to another object. + AddInterface (MakeNewObject ()); +} +void +YetAnotherObject::DoDispose (void) +{ + // Do your work here. + // chain up + Object::DoDispose (); +} + + + int main (int argc, char *argv[]) { Ptr p; Ptr anObject; Ptr anotherObject; + Ptr yetAnotherObject; p = MakeNewObject (); // p gives you access to AnObject's interface @@ -81,5 +110,12 @@ int main (int argc, char *argv[]) NS_ASSERT (anotherObject != 0); + yetAnotherObject = MakeNewObject (2); + // gives you acess to AnObject interface too. + anObject = yetAnotherObject->QueryInterface (AnObject::iid); + NS_ASSERT (anObject != 0); + + return 0; } +