About Store Forum Documentation Contact



Post Reply 
General Question: Chr * vs Chr &
Author Message
Brainache Offline
Member

Post: #1
General Question: Chr * vs Chr &
Hello,

I notice throughout th enegine, you pass data structures by using & instead of *

(for example:
Bool AI::inAttackRange(Chr &chr)
{
return Dist(pos(),chr.pos()) <= ctrl.radius()+chr.ctrl.radius()+0.6;
}
}

I have always passed pointers... ala:
Bool AI:inAttackRange(Char *chr)
{
return Dist(pos(),chr->pos()) <= ctrl.radius()+chr->ctrl.radius()+0.6;
}


Can you enlighten me as to the difference? Is there a performance gain using your method? Is there another reason I should change to using &... and... what exactly is happening when you use &?

Thanks
04-19-2009 02:44 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: General Question: Chr * vs Chr &
there are 2 benefits:
1. you need to use 1 char . instead of 2 chars -> when accessing members
2. using reference (&) forces that you give as parameter an existing object, while pointers (*) can be also set to NULL

so for pointers you should always make additional checks for NULL, and in the references you don't need to
04-19-2009 10:47 AM
Find all posts by this user Quote this message in a reply
Brainache Offline
Member

Post: #3
Re: General Question: Chr * vs Chr &
Allrighty - thanks for satisfying my curiousity!
04-19-2009 02:09 PM
Find all posts by this user Quote this message in a reply
Post Reply