[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] creating an new protocol



Thanks for answer.
I already fixed the problem, but in different way.

First, I initialize the myTimer of Agent in the constructor of myAgent as:

echo_timer(this).

Problem still exists. But when I changed the order of declaration of myAgent 
and myTimer, the problem is gone.

>From: Oliver Dawid <[email protected]>
>To: Yang MinZhen <[email protected]>
>CC: [email protected]
>Subject: Re: [ns] creating an new protocol
>Date: Mon, 30 Jul 2001 23:59:52 +0200 (CEST)
>
>hi,
>
> >
> > I have some question regarding to the example in ns-manual 
>ch9.6(creating an new protocol) as follows:
> >
> >
> > class ECHO_Timer;
> > class ECHO_Agent : public Agent {
> > ....
> > protected:
> > ECHO_Timer echo_timer_;
> > }
> >
> > class ECHO_Timer : public TimerHandler {
> > public:
> > ECHO_Timer(ECHO_Agent *a) : TimerHandler() { a_ = a;}
> > protected:
> > virtual void expire(Event *e)
> > {
> > a_->timeout(0);
> > }
> > ECHO_Agent *a_
> > }
>
>i had the same problem a few weeks ago. you cannot implement expire inline
>- declare the member function and implement it later.
>
>a solution for this is to use a template class, as i wrote some time ago.
>
>template <class X> class TimerA : public TimerHandler {
>public:
>	TimerA(X *a) : TimerHandler() { a_ = a; }
>protected:
>	virtual void expire(Event *e) { a_->timeout(0); }
>	X *a_;
>};
>
>then you can use it in your agent like this:
>
>class MyAgent : public Agent {
>   ...
>protected:
>   ...
>   TimerA<MyAgent> my_timer_;
>   ...
>}
>
>od
>
>--
>    Oliver Dawid * [email protected] * http://www.fet.uni-hannover.de/~od/
>


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp