error: lvalue required as unary ‘&’ operand

18 views
Skip to first unread message

Munde Pravin

unread,
Oct 29, 2017, 11:19:14 AM10/29/17
to ns-3-users
i wrote this function in class RoutingExperiment
void RoutingExperiment::ChangePosition(Ptr<Node> node, double step, double speed)
{
    Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
    Vector v = mob->GetPosition ();
    if(direction==0 && v.x<500)        //to go left
        v.x+=step*speed;
    else if(direction==1 && v.x>0)        //to go right
        v.x-=step*speed;
    else
        return;
    mob->SetPosition(v);
}
in main
Simulator::Schedule(Seconds(0.2), &RoutingExperiment::ChangePosition(adhocNodes.Get(0),2.0,speed),this,Simulator::Now ().GetSeconds ());

and getting this error
error: lvalue required as unary ‘&’ operand

Tommaso Pecorella

unread,
Oct 29, 2017, 1:09:50 PM10/29/17
to ns-3-users
Hi,

the error doesn't seems to belong to the lines you posted.
The compiler should give you the exact location of the error, please double check the lines just before the error.

T.

Munde Pravin

unread,
Oct 30, 2017, 1:30:04 AM10/30/17
to ns-3-users
Hi,
Thanks for replying ,
i have cross-checked the whole code and the error as well,
It seems that i am getting error because of the line Simulator::Schedule only
Regards

pdbarnes

unread,
Oct 30, 2017, 1:51:10 AM10/30/17
to ns-3-users
Looks like it should be:
Simulator::Schedule(Seconds(0.2),
&RoutingExperiment::ChangePosition,
adhocNodes...

Notice that the arguments to ChangePosition() are actually passed to Schedule(), which caches them until the event is executed.

Peter

Munde Pravin

unread,
Oct 30, 2017, 2:34:26 AM10/30/17
to ns-3-users
Hello Sir,
I tried these changes and it worked,
Thank you for replying.
Reply all
Reply to author
Forward
0 new messages